toastr.init.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /******/ (function() { // webpackBootstrap
  2. var __webpack_exports__ = {};
  3. /*!*******************************************!*\
  4. !*** ./resources/js/pages/toastr.init.js ***!
  5. \*******************************************/
  6. /*
  7. Template Name: Skote - Admin & Dashboard Template
  8. Author: Themesbrand
  9. Website: https://themesbrand.com/
  10. Contact: themesbrand@gmail.com
  11. */
  12. // Bootstrap Toast
  13. var toastTrigger = document.getElementById('liveToastBtn');
  14. var toastLiveExample = document.getElementById('liveToast');
  15. if (toastTrigger) {
  16. toastTrigger.addEventListener('click', function () {
  17. var toast = new bootstrap.Toast(toastLiveExample);
  18. toast.show();
  19. });
  20. } // File: Toastr init js
  21. $(function () {
  22. var i = -1;
  23. var toastCount = 0;
  24. var $toastlast;
  25. var getMessage = function getMessage() {
  26. var msgs = ['My name is Inigo Montoya. You killed my father. Prepare to die!', '<div><input class="input-small form-control form-control-sm mb-2" placeholder="textbox"/>&nbsp;<a href="" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary mt-2">Close me</button><button type="button" id="surpriseBtn" class="btn text-white mt-2" style="margin: 0 8px 0 8px">Surprise me</button></div>', 'Are you the six fingered man?', 'Inconceivable!', 'I do not think that means what you think it means.', 'Have fun storming the castle!'];
  27. i++;
  28. if (i === msgs.length) {
  29. i = 0;
  30. }
  31. return msgs[i];
  32. };
  33. var getMessageWithClearButton = function getMessageWithClearButton(msg) {
  34. msg = msg ? msg : 'Clear itself?';
  35. msg += '<br /><br /><button type="button" class="btn-primary btn clear">Yes</button>';
  36. return msg;
  37. };
  38. $('#closeButton').click(function () {
  39. if ($(this).is(':checked')) {
  40. $('#addBehaviorOnToastCloseClick').prop('disabled', false);
  41. } else {
  42. $('#addBehaviorOnToastCloseClick').prop('disabled', true);
  43. $('#addBehaviorOnToastCloseClick').prop('checked', false);
  44. }
  45. });
  46. $('#showtoast').click(function () {
  47. var shortCutFunction = $("#toastTypeGroup input:radio:checked").val();
  48. var msg = $('#message').val();
  49. var title = $('#title').val() || '';
  50. var $showDuration = $('#showDuration');
  51. var $hideDuration = $('#hideDuration');
  52. var $timeOut = $('#timeOut');
  53. var $extendedTimeOut = $('#extendedTimeOut');
  54. var $showEasing = $('#showEasing');
  55. var $hideEasing = $('#hideEasing');
  56. var $showMethod = $('#showMethod');
  57. var $hideMethod = $('#hideMethod');
  58. var toastIndex = toastCount++;
  59. var addClear = $('#addClear').prop('checked');
  60. toastr.options = {
  61. closeButton: $('#closeButton').prop('checked'),
  62. debug: $('#debugInfo').prop('checked'),
  63. newestOnTop: $('#newestOnTop').prop('checked'),
  64. progressBar: $('#progressBar').prop('checked'),
  65. rtl: $('#rtl').prop('checked'),
  66. positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right',
  67. preventDuplicates: $('#preventDuplicates').prop('checked'),
  68. onclick: null
  69. };
  70. if ($('#addBehaviorOnToastClick').prop('checked')) {
  71. toastr.options.onclick = function () {
  72. alert('You can perform some custom action after a toast goes away');
  73. };
  74. }
  75. if ($('#addBehaviorOnToastCloseClick').prop('checked')) {
  76. toastr.options.onCloseClick = function () {
  77. alert('You can perform some custom action when the close button is clicked');
  78. };
  79. }
  80. if ($showDuration.val().length) {
  81. toastr.options.showDuration = parseInt($showDuration.val());
  82. }
  83. if ($hideDuration.val().length) {
  84. toastr.options.hideDuration = parseInt($hideDuration.val());
  85. }
  86. if ($timeOut.val().length) {
  87. toastr.options.timeOut = addClear ? 0 : parseInt($timeOut.val());
  88. }
  89. if ($extendedTimeOut.val().length) {
  90. toastr.options.extendedTimeOut = addClear ? 0 : parseInt($extendedTimeOut.val());
  91. }
  92. if ($showEasing.val().length) {
  93. toastr.options.showEasing = $showEasing.val();
  94. }
  95. if ($hideEasing.val().length) {
  96. toastr.options.hideEasing = $hideEasing.val();
  97. }
  98. if ($showMethod.val().length) {
  99. toastr.options.showMethod = $showMethod.val();
  100. }
  101. if ($hideMethod.val().length) {
  102. toastr.options.hideMethod = $hideMethod.val();
  103. }
  104. if (addClear) {
  105. msg = getMessageWithClearButton(msg);
  106. toastr.options.tapToDismiss = false;
  107. }
  108. if (!msg) {
  109. msg = getMessage();
  110. }
  111. $('#toastrOptions').text('Command: toastr["' + shortCutFunction + '"]("' + msg + (title ? '", "' + title : '') + '")\n\ntoastr.options = ' + JSON.stringify(toastr.options, null, 2));
  112. var $toast = toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists
  113. $toastlast = $toast;
  114. if (typeof $toast === 'undefined') {
  115. return;
  116. }
  117. if ($toast.find('#okBtn').length) {
  118. $toast.delegate('#okBtn', 'click', function () {
  119. alert('you clicked me. i was toast #' + toastIndex + '. goodbye!');
  120. $toast.remove();
  121. });
  122. }
  123. if ($toast.find('#surpriseBtn').length) {
  124. $toast.delegate('#surpriseBtn', 'click', function () {
  125. alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.');
  126. });
  127. }
  128. if ($toast.find('.clear').length) {
  129. $toast.delegate('.clear', 'click', function () {
  130. toastr.clear($toast, {
  131. force: true
  132. });
  133. });
  134. }
  135. });
  136. function getLastToast() {
  137. return $toastlast;
  138. }
  139. $('#clearlasttoast').click(function () {
  140. toastr.clear(getLastToast());
  141. });
  142. $('#cleartoasts').click(function () {
  143. toastr.clear();
  144. });
  145. });
  146. /******/ })()
  147. ;