templates/notification.js.twig line 1

Open in your IDE?
  1. <script type="text/javascript">
  2. /**
  3. * Muestra una notificación temporal
  4. * @param {string} mensaje Mensaje a mostrar
  5. * @param {string} tipo Tipo de notificación (success, error, info)
  6. */
  7. function showNotification(message, type = "info")
  8. {
  9. // Crear el elemento de notificación
  10. const notification = document.createElement("div");
  11. notification.className = `notification notification-${type}`;
  12. notification.innerHTML = `
  13. <span>${message}</span>
  14. <button type="button" class="notification-close" onclick="this.parentNode.remove()">
  15. <i class="fas fa-times"></i>
  16. </button>
  17. `;
  18. // Añadir la notificación al documento
  19. document.body.appendChild(notification);
  20. // Mostrar la notificación
  21. setTimeout(() => {
  22. notification.classList.add("show");
  23. }, 10);
  24. // Ocultar y eliminar la notificación después de un tiempo
  25. setTimeout(() => {
  26. if (notification.parentNode) {
  27. notification.classList.remove('show');
  28. setTimeout(() => {
  29. if (notification.parentNode) {
  30. notification.remove();
  31. }
  32. }, 300);
  33. }
  34. }, 5000);
  35. }
  36. </script>