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.

325 lines
14 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>toastr examples</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  7. <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
  8. <link href="build/toastr.css" rel="stylesheet" type="text/css" />
  9. <style>
  10. .row {
  11. margin-left: 0;
  12. }
  13. </style>
  14. </head>
  15. <body class="container">
  16. <section class="row">
  17. <h1>toastr</h1>
  18. <div class="well row">
  19. <div class="row">
  20. <div class="span4">
  21. <div class="control-group">
  22. <div class="controls">
  23. <label class="control-label" for="title">Title</label>
  24. <input id="title" type="text" class="input-large" placeholder="Enter a title ..." />
  25. <label class="control-label" for="message">Message</label>
  26. <textarea class="input-large" id="message" rows="3" placeholder="Enter a message ..."></textarea>
  27. </div>
  28. </div>
  29. <div class="control-group">
  30. <div class="controls">
  31. <label class="checkbox" for="closeButton">
  32. <input id="closeButton" type="checkbox" value="checked" class="input-mini" />Close Button
  33. </label>
  34. </div>
  35. <div class="controls">
  36. <label class="checkbox" for="addBehaviorOnToastClick">
  37. <input id="addBehaviorOnToastClick" type="checkbox" value="checked" class="input-mini" />Add behavior on toast click
  38. </label>
  39. </div>
  40. <div class="controls">
  41. <label class="checkbox" for="debugInfo">
  42. <input id="debugInfo" type="checkbox" value="checked" class="input-mini" />Debug
  43. </label>
  44. </div>
  45. <div class="controls">
  46. <label class="checkbox" for="progressBar">
  47. <input id="progressBar" type="checkbox" value="checked" class="input-mini" />Progress Bar
  48. </label>
  49. </div>
  50. <div class="controls">
  51. <label class="checkbox" for="preventDuplicates">
  52. <input id="preventDuplicates" type="checkbox" value="checked" class="input-mini" />Prevent Duplicates
  53. </label>
  54. </div>
  55. <div class="controls">
  56. <label class="checkbox" for="addClear">
  57. <input id="addClear" type="checkbox" value="checked" class="input-mini" />Add button to force clearing a toast, ignoring focus
  58. </label>
  59. </div>
  60. <div class="controls">
  61. <label class="checkbox" for="newestOnTop">
  62. <input id="newestOnTop" type="checkbox" value="checked" class="input-mini" />Newest on top
  63. </label>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="span2">
  68. <div class="control-group" id="toastTypeGroup">
  69. <div class="controls">
  70. <label>Toast Type</label>
  71. <label class="radio">
  72. <input type="radio" name="toasts" value="success" checked />Success
  73. </label>
  74. <label class="radio">
  75. <input type="radio" name="toasts" value="info" />Info
  76. </label>
  77. <label class="radio">
  78. <input type="radio" name="toasts" value="warning" />Warning
  79. </label>
  80. <label class="radio">
  81. <input type="radio" name="toasts" value="error" />Error
  82. </label>
  83. </div>
  84. </div>
  85. <div class="control-group" id="positionGroup">
  86. <div class="controls">
  87. <label>Position</label>
  88. <label class="radio">
  89. <input type="radio" name="positions" value="toast-top-right" checked />Top Right
  90. </label>
  91. <label class="radio">
  92. <input type="radio" name="positions" value="toast-bottom-right" />Bottom Right
  93. </label>
  94. <label class="radio">
  95. <input type="radio" name="positions" value="toast-bottom-left" />Bottom Left
  96. </label>
  97. <label class="radio">
  98. <input type="radio" name="positions" value="toast-top-left" />Top Left
  99. </label>
  100. <label class="radio">
  101. <input type="radio" name="positions" value="toast-top-full-width" />Top Full Width
  102. </label>
  103. <label class="radio">
  104. <input type="radio" name="positions" value="toast-bottom-full-width" />Bottom Full Width
  105. </label>
  106. <label class="radio">
  107. <input type="radio" name="positions" value="toast-top-center" />Top Center
  108. </label>
  109. <label class="radio">
  110. <input type="radio" name="positions" value="toast-bottom-center" />Bottom Center
  111. </label>
  112. </div>
  113. </div>
  114. </div>
  115. <div class="span2">
  116. <div class="control-group">
  117. <div class="controls">
  118. <label class="control-label" for="showEasing">Show Easing</label>
  119. <input id="showEasing" type="text" placeholder="swing, linear" class="input-mini" value="swing" />
  120. <label class="control-label" for="hideEasing">Hide Easing</label>
  121. <input id="hideEasing" type="text" placeholder="swing, linear" class="input-mini" value="linear" />
  122. <label class="control-label" for="showMethod">Show Method</label>
  123. <input id="showMethod" type="text" placeholder="show, fadeIn, slideDown" class="input-mini" value="fadeIn" />
  124. <label class="control-label" for="hideMethod">Hide Method</label>
  125. <input id="hideMethod" type="text" placeholder="hide, fadeOut, slideUp" class="input-mini" value="fadeOut" />
  126. </div>
  127. </div>
  128. </div>
  129. <div class="span3">
  130. <div class="control-group">
  131. <div class="controls">
  132. <label class="control-label" for="showDuration">Show Duration</label>
  133. <input id="showDuration" type="text" placeholder="ms" class="input-mini" value="300" />
  134. <label class="control-label" for="hideDuration">Hide Duration</label>
  135. <input id="hideDuration" type="text" placeholder="ms" class="input-mini" value="1000" />
  136. <label class="control-label" for="timeOut">Time out</label>
  137. <input id="timeOut" type="text" placeholder="ms" class="input-mini" value="5000" />
  138. <label class="control-label" for="extendedTimeOut">Extended time out</label>
  139. <input id="extendedTimeOut" type="text" placeholder="ms" class="input-mini" value="1000" />
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="row">
  145. <button type="button" class="btn btn-primary" id="showtoast">Show Toast</button>
  146. <button type="button" class="btn btn-danger" id="cleartoasts">Clear Toasts</button>
  147. <button type="button" class="btn btn-danger" id="clearlasttoast">Clear Last Toast</button>
  148. </div>
  149. <div class="row" style='margin-top: 25px;'>
  150. <pre id='toastrOptions'></pre>
  151. </div>
  152. </div>
  153. </section>
  154. <footer class="row">
  155. <h2>Links</h2>
  156. <ul>
  157. <li><a href="http://nuget.org/packages/toastr">NuGet</a></li>
  158. <li><a href="https://github.com/CodeSeven/toastr">GitHub</a></li>
  159. </ul>
  160. </footer>
  161. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  162. <script src="toastr.js"></script>
  163. <script type="text/javascript">
  164. $(function () {
  165. var i = -1;
  166. var toastCount = 0;
  167. var $toastlast;
  168. var getMessage = function () {
  169. var msgs = ['My name is Inigo Montoya. You killed my father. Prepare to die!',
  170. '<div><input class="input-small" value="textbox"/>&nbsp;<a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="surpriseBtn" class="btn" style="margin: 0 8px 0 8px">Surprise me</button></div>',
  171. 'Are you the six fingered man?',
  172. 'Inconceivable!',
  173. 'I do not think that means what you think it means.',
  174. 'Have fun storming the castle!'
  175. ];
  176. i++;
  177. if (i === msgs.length) {
  178. i = 0;
  179. }
  180. return msgs[i];
  181. };
  182. var getMessageWithClearButton = function (msg) {
  183. msg = msg ? msg : 'Clear itself?';
  184. msg += '<br /><br /><button type="button" class="btn clear">Yes</button>';
  185. return msg;
  186. };
  187. $('#showtoast').click(function () {
  188. var shortCutFunction = $("#toastTypeGroup input:radio:checked").val();
  189. var msg = $('#message').val();
  190. var title = $('#title').val() || '';
  191. var $showDuration = $('#showDuration');
  192. var $hideDuration = $('#hideDuration');
  193. var $timeOut = $('#timeOut');
  194. var $extendedTimeOut = $('#extendedTimeOut');
  195. var $showEasing = $('#showEasing');
  196. var $hideEasing = $('#hideEasing');
  197. var $showMethod = $('#showMethod');
  198. var $hideMethod = $('#hideMethod');
  199. var toastIndex = toastCount++;
  200. var addClear = $('#addClear').prop('checked');
  201. toastr.options = {
  202. closeButton: $('#closeButton').prop('checked'),
  203. debug: $('#debugInfo').prop('checked'),
  204. newestOnTop: $('#newestOnTop').prop('checked'),
  205. progressBar: $('#progressBar').prop('checked'),
  206. positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right',
  207. preventDuplicates: $('#preventDuplicates').prop('checked'),
  208. onclick: null
  209. };
  210. if ($('#addBehaviorOnToastClick').prop('checked')) {
  211. toastr.options.onclick = function () {
  212. alert('You can perform some custom action after a toast goes away');
  213. };
  214. }
  215. if ($showDuration.val().length) {
  216. toastr.options.showDuration = $showDuration.val();
  217. }
  218. if ($hideDuration.val().length) {
  219. toastr.options.hideDuration = $hideDuration.val();
  220. }
  221. if ($timeOut.val().length) {
  222. toastr.options.timeOut = addClear ? 0 : $timeOut.val();
  223. }
  224. if ($extendedTimeOut.val().length) {
  225. toastr.options.extendedTimeOut = addClear ? 0 : $extendedTimeOut.val();
  226. }
  227. if ($showEasing.val().length) {
  228. toastr.options.showEasing = $showEasing.val();
  229. }
  230. if ($hideEasing.val().length) {
  231. toastr.options.hideEasing = $hideEasing.val();
  232. }
  233. if ($showMethod.val().length) {
  234. toastr.options.showMethod = $showMethod.val();
  235. }
  236. if ($hideMethod.val().length) {
  237. toastr.options.hideMethod = $hideMethod.val();
  238. }
  239. if (addClear) {
  240. msg = getMessageWithClearButton(msg);
  241. toastr.options.tapToDismiss = false;
  242. }
  243. if (!msg) {
  244. msg = getMessage();
  245. }
  246. $('#toastrOptions').text('Command: toastr["'
  247. + shortCutFunction
  248. + '"]("'
  249. + msg
  250. + (title ? '", "' + title : '')
  251. + '")\n\ntoastr.options = '
  252. + JSON.stringify(toastr.options, null, 2)
  253. );
  254. var $toast = toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists
  255. $toastlast = $toast;
  256. if(typeof $toast === 'undefined'){
  257. return;
  258. }
  259. if ($toast.find('#okBtn').length) {
  260. $toast.delegate('#okBtn', 'click', function () {
  261. alert('you clicked me. i was toast #' + toastIndex + '. goodbye!');
  262. $toast.remove();
  263. });
  264. }
  265. if ($toast.find('#surpriseBtn').length) {
  266. $toast.delegate('#surpriseBtn', 'click', function () {
  267. alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.');
  268. });
  269. }
  270. if ($toast.find('.clear').length) {
  271. $toast.delegate('.clear', 'click', function () {
  272. toastr.clear($toast, { force: true });
  273. });
  274. }
  275. });
  276. function getLastToast(){
  277. return $toastlast;
  278. }
  279. $('#clearlasttoast').click(function () {
  280. toastr.clear(getLastToast());
  281. });
  282. $('#cleartoasts').click(function () {
  283. toastr.clear();
  284. });
  285. })
  286. </script>
  287. </body>
  288. </html>