You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.1 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # toastr
  2. **toastr** is a Javascript library for non-blocking notifications. jQuery is required. The goal is to create a simple core library that can be customized and extended.
  3. [![Build Status](https://travis-ci.org/CodeSeven/toastr.svg)](https://travis-ci.org/CodeSeven/toastr)
  4. Browser testing provided by BrowserStack.
  5. ## Current Version
  6. 2.1.3
  7. ## Demo
  8. - Demo can be found at http://codeseven.github.io/toastr/demo.html
  9. - [Demo using FontAwesome icons with toastr](http://plnkr.co/edit/6W9URNyyp2ItO4aUWzBB?p=preview)
  10. ## [CDNjs](https://cdnjs.com/libraries/toastr.js)
  11. Toastr is hosted at CDN JS
  12. #### Debug
  13. - [//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js](//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.js)
  14. - [//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css](//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css)
  15. #### Minified
  16. - [//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js](//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js)
  17. - [//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css](//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css)
  18. ## Install
  19. #### [NuGet Gallery](http://nuget.org/packages/toastr)
  20. ```
  21. Install-Package toastr
  22. ```
  23. #### [Bower](http://bower.io/search/?q=toastr)
  24. ```
  25. bower install toastr
  26. ```
  27. #### [npm](https://www.npmjs.com/package/toastr)
  28. ```
  29. npm install --save toastr
  30. ```
  31. ## Wiki and Change Log
  32. [Wiki including Change Log](https://github.com/CodeSeven/toastr/wiki)
  33. ## Breaking Changes
  34. ####Animation Changes
  35. The following animations options have been deprecated and should be replaced:
  36. - Replace `options.fadeIn` with `options.showDuration`
  37. - Replace `options.onFadeIn` with `options.onShown`
  38. - Replace `options.fadeOut` with `options.hideDuration`
  39. - Replace `options.onFadeOut` with `options.onHidden`
  40. ## Quick Start
  41. ### 3 Easy Steps
  42. For other API calls, see the [demo](http://codeseven.github.io/toastr/demo.html).
  43. 1. Link to toastr.css `<link href="toastr.css" rel="stylesheet"/>`
  44. 2. Link to toastr.js `<script src="toastr.js"></script>`
  45. 3. use toastr to display a toast for info, success, warning or error
  46. ```js
  47. // Display an info toast with no title
  48. toastr.info('Are you the 6 fingered man?')
  49. ```
  50. ### Other Options
  51. ```js
  52. // Display a warning toast, with no title
  53. toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!')
  54. // Display a success toast, with a title
  55. toastr.success('Have fun storming the castle!', 'Miracle Max Says')
  56. // Display an error toast, with a title
  57. toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')
  58. // Immediately remove current toasts without using animation
  59. toastr.remove()
  60. // Remove current toasts using animation
  61. toastr.clear()
  62. // Override global options
  63. toastr.success('We do have the Kapua suite available.', 'Turtle Bay Resort', {timeOut: 5000})
  64. ```
  65. ### Escape HTML characters
  66. In case you want to escape HTML charaters in title and message
  67. toastr.options.escapeHtml = true;
  68. ### Close Button
  69. Optionally enable a close button
  70. ```js
  71. toastr.options.closeButton = true;
  72. ````
  73. Optionally override the close button's HTML.
  74. ```js
  75. toastr.options.closeHtml = '<button><i class="icon-off"></i></button>';
  76. ```
  77. You can also override the CSS/LESS for `#toast-container .toast-close-button`
  78. Optionally override the hide animation when the close button is clicked (falls back to hide configuration).
  79. ```js
  80. toastr.options.closeMethod = 'fadeOut';
  81. toastr.options.closeDuration = 300;
  82. toastr.options.closeEasing = 'swing';
  83. ```
  84. ### Display Sequence
  85. Show newest toast at bottom (top is default)
  86. ```js
  87. toastr.options.newestOnTop = false;
  88. ```
  89. ### Callbacks
  90. ```js
  91. // Define a callback for when the toast is shown/hidden/clicked
  92. toastr.options.onShown = function() { console.log('hello'); }
  93. toastr.options.onHidden = function() { console.log('goodbye'); }
  94. toastr.options.onclick = function() { console.log('clicked'); }
  95. toastr.options.onCloseClick = function() { console.log('close button clicked'); }
  96. ```
  97. ### Animation Options
  98. Toastr will supply default animations, so you do not have to provide any of these settings. However you have the option to override the animations if you like.
  99. ####Easings
  100. Optionally override the animation easing to show or hide the toasts. Default is swing. swing and linear are built into jQuery.
  101. ```js
  102. toastr.options.showEasing = 'swing';
  103. toastr.options.hideEasing = 'linear';
  104. toastr.options.closeEasing = 'linear';
  105. ```
  106. Using the jQuery Easing plugin (http://www.gsgd.co.uk/sandbox/jquery/easing/)
  107. ```js
  108. toastr.options.showEasing = 'easeOutBounce';
  109. toastr.options.hideEasing = 'easeInBack';
  110. toastr.options.closeEasing = 'easeInBack';
  111. ```
  112. ####Animation Method
  113. Use the jQuery show/hide method of your choice. These default to fadeIn/fadeOut. The methods fadeIn/fadeOut, slideDown/slideUp, and show/hide are built into jQuery.
  114. ```js
  115. toastr.options.showMethod = 'slideDown';
  116. toastr.options.hideMethod = 'slideUp';
  117. toastr.options.closeMethod = 'slideUp';
  118. ```
  119. ###Prevent Duplicates
  120. Rather than having identical toasts stack, set the preventDuplicates property to true. Duplicates are matched to the previous toast based on their message content.
  121. ```js
  122. toastr.options.preventDuplicates = true;
  123. ```
  124. ###Timeouts
  125. Control how toastr interacts with users by setting timeouts appropriately. Timeouts can be disabled by setting them to 0.
  126. ```js
  127. toastr.options.timeOut = 30; // How long the toast will display without user interaction
  128. toastr.options.extendedTimeOut = 60; // How long the toast will display after a user hovers over it
  129. ```
  130. ###Progress Bar
  131. Visually indicate how long before a toast expires.
  132. ```js
  133. toastr.options.progressBar = true;
  134. ```
  135. ### rtl
  136. Flip the toastr to be displayed properly for right-to-left languages.
  137. ```js
  138. toastr.options.rtl = true;
  139. ```
  140. ## Building Toastr
  141. To build the minified and css versions of Toastr you will need [node](http://nodejs.org) installed. (Use Homebrew or Chocolatey.)
  142. ```
  143. npm install -g gulp karma-cli
  144. npm install
  145. ```
  146. At this point the dependencies have been installed and you can build Toastr
  147. - Run the analytics `gulp analyze`
  148. - Run the test `gulp test`
  149. - Run the build `gulp`
  150. ## Contributing
  151. For a pull request to be considered it must resolve a bug, or add a feature which is beneficial to a large audience.
  152. Pull requests must pass existing unit tests, CI processes, and add additional tests to indicate successful operation of a new feature, or the resolution of an identified bug.
  153. Requests must be made against the `develop` branch. Pull requests submitted against the `master` branch will not be considered.
  154. All pull requests are subject to approval by the repository owners, who have sole discretion over acceptance or denial.
  155. ## Authors
  156. **John Papa**
  157. + [http://twitter.com/John_Papa](http://twitter.com/John_Papa)
  158. **Tim Ferrell**
  159. + [http://twitter.com/ferrell_tim](http://twitter.com/ferrell_tim)
  160. **Hans Fjällemark**
  161. + [http://twitter.com/hfjallemark](http://twitter.com/hfjallemark)
  162. ## Credits
  163. Inspired by https://github.com/Srirangan/notifer.js/.
  164. ## Copyright
  165. Copyright © 2012-2015
  166. ## License
  167. toastr is under MIT license - http://www.opensource.org/licenses/mit-license.php