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.

147 lines
6.6 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. # Jquery Toast Plugin
  2. A plugin to show highly customizable notifications to the user.
  3. <img src="http://i.imgur.com/RRrb0KE.png" />
  4. # How to use
  5. - You can install the plugin via Bower:
  6. ```js
  7. bower install jquery-toast-plugin
  8. ```
  9. or via `npm`
  10. ```js
  11. npm install jquery-toast-plugin
  12. ```
  13. Or directly download the repository and place the content of `dist` wherever you can access them.
  14. - Include the CSS and JS files.
  15. - Simply do ```$.toast('Toast message to be shown')``` Of course it would be the world's simplest toast message but believe me **you can do a lot more** with the options.
  16. # Demo
  17. For some quick demos and a detailed documentation accompanied by the demos for each of the available options can be accessed through http://kamranahmed.info/toast
  18. ## Quick usage examples
  19. **Simple textual toast**
  20. ```javascript
  21. // Non sticky version
  22. $.toast("Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic, consequuntur doloremque eveniet eius eaque dicta repudiandae illo ullam. Minima itaque sint magnam dolorum asperiores repudiandae dignissimos expedita, voluptatum vitae velit.")
  23. // Sticky version
  24. $.toast({
  25. text : "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic, consequuntur doloremque eveniet eius eaque dicta repudiandae illo ullam. Minima itaque sint magnam dolorum asperiores repudiandae dignissimos expedita, voluptatum vitae velit.",
  26. hideAfter : false
  27. })
  28. ```
  29. **Toast using HTML as a text**
  30. ```javascript
  31. // Non sticky
  32. $.toast("Let's test some HTML stuff... <a href='#'>github</a>")
  33. // sticky
  34. $.toast({
  35. text : "<strong>Remember!</strong> You can <span style='font-weight: bold; color:red;' class='horribly-styled'>always</span> introduce your own × HTML and <span style='font-size: 18px;'>CSS</span> in the toast.",
  36. hideAfter : false
  37. })
  38. ```
  39. **Unordered list elements as the text of toast using array**
  40. ```javascript
  41. // Non sticky version
  42. $.toast(["Ubuntu : One of it's kind", "Sublime Text : Productivity unleashed", "HeidiSQL : Just love it", "Github : Just Lovely"])
  43. // Sticky version
  44. $.toast({
  45. text : ["Ubuntu : One of it's kind", "Sublime Text : Productivity unleashed", "HeidiSQL : Just love it", "Github : Just Lovely"],
  46. hideAfter : false
  47. })
  48. ```
  49. **Changing the animations**
  50. ```javascript
  51. $.toast({
  52. text : "Let's test some HTML stuff... <a href='#'>github</a>",
  53. showHideTransition : 'slide' // It can be plain, fade or slide
  54. })
  55. ```
  56. **Changing the formatting**
  57. ```javascript
  58. $.toast({
  59. text : "Let's test some HTML stuff... <a href='#'>github</a>",
  60. showHideTransition : 'slide', // It can be plain, fade or slide
  61. bgColor : 'blue', // Background color for toast
  62. textColor : '#eee', // text color
  63. allowToastClose : false, // Show the close button or not
  64. hideAfter : 5000, // `false` to make it sticky or time in miliseconds to hide after
  65. stack : 5, // `fakse` to show one stack at a time count showing the number of toasts that can be shown at once
  66. textAlign : 'left', // Alignment of text i.e. left, right, center
  67. position : 'bottom-left' // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values to position the toast on page
  68. })
  69. ```
  70. **Resetting the toast**
  71. ```javascript
  72. var myToast = $.toast('Some toast that needs to be removed.');
  73. myToast.reset(); // remove the toast "Some toast that needs to be removed"
  74. ```
  75. What if I want to reset all the toasts at once? You may ask. Well in that case, you can do the following:
  76. ```javascript
  77. $.toast().reset('all');
  78. ```
  79. **Updating the toast**
  80. Suppose, you had shown some toast upon the page, a sticky toast for example and now you want to update the toast. You can do the following
  81. ```javascript
  82. var myToast = $.toast({
  83. text : 'Some toast that needs to show the success message after the ajax call.',
  84. hideAfter : false,
  85. bgColor : '#E01A31'
  86. });
  87. window.setTimeout(function(){
  88. myToast.update({
  89. text : '<strong>Updated after a few seconds</strong>',
  90. bgColor : '#23B65D'
  91. });
  92. }, 5000);
  93. ```
  94. To learn more about how to use and customize it, head to <a href="http://kamranahmed.info/toast" target="_blank">http://kamranahmed.info/toast</a>. Also you can find a customizer there that will let you modify the look and feel of the toast however you like it.
  95. <hr>
  96. You can simply download the repo or if you are in rush the <a href="https://raw.githubusercontent.com/kamranahmedse/jquery-toast-plugin/master/jquery.toast.min.css" target="_blank">minified CSS</a> or <a href="https://raw.githubusercontent.com/kamranahmedse/jquery-toast-plugin/master/jquery.toast.css">non-minified CSS</a> can be found and <a href="https://raw.githubusercontent.com/kamranahmedse/jquery-toast-plugin/master/jquery.toast.min.js" target="_blank">minified JS</a> and <a href="https://raw.githubusercontent.com/kamranahmedse/jquery-toast-plugin/master/jquery.toast.js" target="_blank">non minified JS</a> can also be found.
  97. # Features
  98. <ul>
  99. <li>Show different types of toasts i.e. informational, warning, errors and success</li>
  100. <li>Custom <strong>toast background color</strong> and <strong>text color</strong></li>
  101. <li>Ability to <strong>hack the CSS</strong> to add your own thing</li>
  102. <li>
  103. <strong>Text can be</strong> provided in the form of
  104. <ul>
  105. <li><strong>Array</strong> (It's elements will be changed to an un ordered list)</li>
  106. <li><strong>Simple text</strong></li>
  107. <li><strong>HTML</strong></li>
  108. </ul>
  109. </li>
  110. <li><strong>Events support</strong> i.e. <code>beforeHide</code>, <code>afterHidden</code>, <code>beforeShow</code>, <code>afterShown</code></li>
  111. <li><code>Fade</code> and <code>Slide</code> show/hide transitions support (More to come)</li>
  112. <li>Supports showing the loader for the toast</li>
  113. <li>You can <strong>position the toast, wherever you want</strong> there is support for <code>top-left</code>, <code>top-right</code> <code>bottom-left</code> and <strong>bottom-right</strong>, <code>top-center</code>, <code>bottom-center</code> and <code>mid-center</code> ...sighs! That's a whole lot of options, isn't it? No, you say. Ok then here is the most exciting thing, you can also introduce <strong>your own positioning</strong> just <strong>by passing a simple js object</strong> containing <code>{ top: - , bottom: -, left: -, right: - }</code> </li>
  114. <li>Ability to add <strong>sticky toast</strong></li>
  115. <li>Optional <strong>stack length can be defined</strong> (i.e. maximum number of toasts that can be shown at once)</li>
  116. </ul>
  117. Please report any bugs or features you would like added.
  118. # Copyright
  119. MIT © [Kamran Ahmed](http://kamranahmed.info)