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.

220 lines
6.8 KiB

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