Sin descripción
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. * UI Toasts
  3. */
  4. 'use strict';
  5. document.addEventListener('DOMContentLoaded', function (e) {
  6. // Bootstrap toasts example
  7. // --------------------------------------------------------------------
  8. const toastAnimationExample = document.querySelector('.toast-ex'),
  9. toastPlacementExample = document.querySelector('.toast-placement-ex'),
  10. toastAnimationBtn = document.querySelector('#showToastAnimation'),
  11. toastPlacementBtn = document.querySelector('#showToastPlacement');
  12. let selectedType, selectedAnimation, selectedPlacement, toast, toastAnimation, toastPlacement;
  13. // Animation Button click
  14. if (toastAnimationBtn) {
  15. toastAnimationBtn.onclick = function () {
  16. if (toastAnimation) {
  17. toastDispose(toastAnimation);
  18. }
  19. selectedType = document.querySelector('#selectType').value;
  20. selectedAnimation = document.querySelector('#selectAnimation').value;
  21. toastAnimationExample.classList.add(selectedType, selectedAnimation);
  22. toastAnimation = new bootstrap.Toast(toastAnimationExample);
  23. toastAnimation.show();
  24. };
  25. }
  26. // Dispose toast when open another
  27. function toastDispose(toast) {
  28. if (toast && toast._element !== null) {
  29. if (toastPlacementExample) {
  30. toastPlacementExample.classList.remove(selectedType);
  31. DOMTokenList.prototype.remove.apply(toastPlacementExample.classList, selectedPlacement);
  32. }
  33. if (toastAnimationExample) {
  34. toastAnimationExample.classList.remove(selectedType, selectedAnimation);
  35. }
  36. toast.dispose();
  37. }
  38. }
  39. // Placement Button click
  40. if (toastPlacementBtn) {
  41. toastPlacementBtn.onclick = function () {
  42. if (toastPlacement) {
  43. toastDispose(toastPlacement);
  44. }
  45. selectedType = document.querySelector('#selectTypeOpt').value;
  46. selectedPlacement = document.querySelector('#selectPlacement').value.split(' ');
  47. toastPlacementExample.classList.add(selectedType);
  48. DOMTokenList.prototype.add.apply(toastPlacementExample.classList, selectedPlacement);
  49. toastPlacement = new bootstrap.Toast(toastPlacementExample);
  50. toastPlacement.show();
  51. };
  52. }
  53. //notyf (js)
  54. // --------------------------------------------------------------------
  55. // Initialize message index
  56. let i = -1;
  57. // Function to cycle through messages
  58. const getMessage = function () {
  59. const msgs = [
  60. "Don't be pushed around by the fears in your mind. Be led by the dreams in your heart.",
  61. '<div class="mb-3"><input class="input-small form-control" value="Textbox"/>&nbsp;<a href="http://example.com" target="_blank" class="text-white">This is a hyperlink</a></div><div class="d-flex"><button type="button" id="okBtn" class="btn btn-primary btn-sm me-2">Close me</button><button type="button" id="surpriseBtn" class="btn btn-sm btn-secondary">Surprise me</button></div>',
  62. 'Live the Life of Your Dreams',
  63. 'Believe in Yourself!',
  64. 'Be mindful. Be grateful. Be positive.',
  65. 'Accept yourself, love yourself!'
  66. ];
  67. i = (i + 1) % msgs.length;
  68. return msgs[i];
  69. };
  70. // Custom Notyf class to allow HTML content in messages
  71. class CustomNotyf extends Notyf {
  72. _renderNotification(options) {
  73. const notification = super._renderNotification(options);
  74. // Replace textContent with innerHTML to render HTML content
  75. if (options.message) {
  76. notification.message.innerHTML = options.message;
  77. }
  78. return notification;
  79. }
  80. }
  81. // Initialize CustomNotyf instance with default behaviors
  82. const notyf = new CustomNotyf({
  83. duration: 3000,
  84. ripple: true,
  85. dismissible: false,
  86. position: { x: 'right', y: 'top' },
  87. types: [
  88. {
  89. type: 'info',
  90. background: config.colors.info,
  91. className: 'notyf__info',
  92. icon: {
  93. className: 'icon-base bx bxs-info-circle icon-md text-white',
  94. tagName: 'i'
  95. }
  96. },
  97. {
  98. type: 'warning',
  99. background: config.colors.warning,
  100. className: 'notyf__warning',
  101. icon: {
  102. className: 'icon-base bx bxs-error icon-md text-white',
  103. tagName: 'i'
  104. }
  105. },
  106. {
  107. type: 'success',
  108. background: config.colors.success,
  109. className: 'notyf__success',
  110. icon: {
  111. className: 'icon-base bx bxs-check-circle icon-md text-white',
  112. tagName: 'i'
  113. }
  114. },
  115. {
  116. type: 'error',
  117. background: config.colors.danger,
  118. className: 'notyf__error',
  119. icon: {
  120. className: 'icon-base bx bxs-x-circle icon-md text-white',
  121. tagName: 'i'
  122. }
  123. }
  124. ]
  125. });
  126. // Event listener for Show Notification button
  127. document.getElementById('showNotification').addEventListener('click', () => {
  128. const message = document.getElementById('message').value || getMessage(); // Use getMessage() to get the next message
  129. const dismissible = document.getElementById('dismissible').checked;
  130. const ripple = document.getElementById('ripple').checked;
  131. const durationInput = document.getElementById('duration').value;
  132. const duration = durationInput ? parseInt(durationInput) : 3000;
  133. // Get selected position
  134. const positionYValue = document.querySelector('input[name="positiony"]:checked').value;
  135. const positionXValue = document.querySelector('input[name="positionx"]:checked').value;
  136. const position = { x: positionXValue, y: positionYValue };
  137. // Get selected notification type
  138. const type = document.querySelector('input[name="notificationType"]:checked').value;
  139. // Build the notification options
  140. const notificationOptions = {
  141. type: type,
  142. message: message,
  143. duration: duration,
  144. dismissible: dismissible,
  145. ripple: ripple,
  146. position: position
  147. };
  148. // Display notification and get the reference
  149. attachNotificationEventListeners();
  150. notyf.open(notificationOptions);
  151. });
  152. // Event listener for Clear Notifications button
  153. document.getElementById('clearNotifications').addEventListener('click', () => {
  154. notyf.dismissAll();
  155. });
  156. // Function to attach event listeners to elements inside the notification
  157. function attachNotificationEventListeners() {
  158. // Wait for the DOM to update
  159. setTimeout(() => {
  160. const okBtn = document.getElementById('okBtn');
  161. const surpriseBtn = document.getElementById('surpriseBtn');
  162. if (okBtn) {
  163. okBtn.addEventListener('click', () => {
  164. notyf.dismissAll(); // Close all notifications
  165. });
  166. }
  167. if (surpriseBtn) {
  168. surpriseBtn.addEventListener('click', () => {
  169. notyf.success('Surprise! This is a new message.');
  170. });
  171. }
  172. }, 100);
  173. }
  174. });