(function () { // =============================== // Utility: Close toast function // =============================== function closeToastMagicItem(toast) { toast.classList.remove("show"); setTimeout(() => { toast.remove(); }, 500); } // =============================== // Utility: Icon generator // =============================== function getToasterIcon(key = null) { if (key?.toString() === 'success') { return ` `; } else if (key?.toString() === 'error') { return ``; } else if (key?.toString() === 'info') { return ``; } else if (key?.toString() === 'warning') { return ``; } else if (key?.toString() === 'close') { return ``; } else { return ``; } } // =============================== // ToastMagic Class Definition // =============================== if (typeof window.ToastMagic === "undefined") { window.ToastMagic = class ToastMagic { constructor() { const config = window.toastMagicConfig || {}; this.toastMagicPosition = config.positionClass || "toast-top-end"; this.toastMagicCloseButton = config.closeButton || false; this.toastMagicTheme = config.theme || 'default'; this.toastContainer = document.querySelector(".toast-container"); if (!this.toastContainer) { this.toastContainer = document.createElement("div"); this.toastContainer.classList.add("toast-container"); document.body.appendChild(this.toastContainer); } this.toastContainer.className = "toast-container " + this.toastMagicPosition + " theme-" + this.toastMagicTheme; } show({ type, heading, description = "", showCloseBtn = this.toastMagicCloseButton, customBtnText = "", customBtnLink = "" }) { let toastClass, toastClassBasic; switch (type) { case "success": toastClass = "toast-success"; toastClassBasic = "success"; break; case "error": toastClass = "toast-danger"; toastClassBasic = "danger"; break; case "warning": toastClass = "toast-warning"; toastClassBasic = "warning"; break; case "info": default: toastClass = "toast-info"; toastClassBasic = "info"; } const toast = document.createElement("div"); toast.classList.add("toast-item", toastClass); toast.setAttribute("role", "alert"); toast.setAttribute("aria-live", "assertive"); toast.setAttribute("aria-atomic", "true"); toast.innerHTML = `
${description}
` : ''}