1 line
2.0 KiB
JavaScript
1 line
2.0 KiB
JavaScript
(function(){'use strict';let notificationContainer = null;function initNotifications(){if(!notificationContainer){notificationContainer = document.createElement('div');notificationContainer.id = 'simple-notifications';notificationContainer.className = 'fixed top-4 right-4 z-50 space-y-2 max-w-sm';document.body.appendChild(notificationContainer);}}window.showNotification = function(message,type = 'info',duration = 5000){initNotifications();const notification = document.createElement('div');notification.className = 'notification-simple notification-enter fade-in';const icons ={success:'fa-check-circle',error:'fa-exclamation-circle',warning:'fa-exclamation-triangle',info:'fa-info-circle'};notification.innerHTML = ` <div class="notification-content"> <i class="fas ${icons[type]}notification-icon ${type}"></i> <span class="notification-message">${message}</span> </div> <button class="notification-close" aria-label="Schließen"> <i class="fas fa-times"></i> </button> `;notificationContainer.appendChild(notification);setTimeout(()=>{notification.classList.remove('notification-enter');notification.classList.add('notification-enter-active');},10);const closeBtn = notification.querySelector('.notification-close');closeBtn.addEventListener('click',()=> removeNotification(notification));if(duration > 0){setTimeout(()=> removeNotification(notification),duration);}return notification;};function removeNotification(notification){notification.classList.add('notification-exit');setTimeout(()=>{if(notification.parentNode){notification.parentNode.removeChild(notification);}},200);}window.notifySuccess =(message,duration)=> showNotification(message,'success',duration);window.notifyError =(message,duration)=> showNotification(message,'error',duration);window.notifyWarning =(message,duration)=> showNotification(message,'warning',duration);window.notifyInfo =(message,duration)=> showNotification(message,'info',duration);if(typeof window.showToast === 'function'){window.showToast = function(message,type,duration){showNotification(message,type,duration);};}})(); |