1(function () { 2 // =============================== 3 // Utility: Close toast function 4 // =============================== 5 function closeToastMagicItem(toast) { 6 toast.classList.remove("show"); 7 setTimeout(() => { 8 toast.remove(); 9 }, 500); 10 } 11 12 // =============================== 13 // Utility: Icon generator 14 // =============================== 15 function getToasterIcon(key = null) { 16 if (key?.toString() === 'success') { 17 return `<?xml version="1.0" encoding="UTF-8"?> 18<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve" width="28" height="28"> 19<g><path fill="currentColor" d="M405.333,0H106.667C47.786,0.071,0.071,47.786,0,106.667v298.667C0.071,464.214,47.786,511.93,106.667,512h298.667 C464.214,511.93,511.93,464.214,512,405.333V106.667C511.93,47.786,464.214,0.071,405.333,0z M426.667,172.352L229.248,369.771 c-16.659,16.666-43.674,16.671-60.34,0.012c-0.004-0.004-0.008-0.008-0.012-0.012l-83.563-83.541 c-8.348-8.348-8.348-21.882,0-30.229s21.882-8.348,30.229,0l83.541,83.541l197.44-197.419c8.348-8.318,21.858-8.294,30.176,0.053 C435.038,150.524,435.014,164.034,426.667,172.352z"/></g></svg> 20`; 21 } else if (key?.toString() === 'error') { 22 return `<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 24 24" width="28" height="28"><path fill="currentColor" d="m19,0H5C2.243,0,0,2.243,0,5v14c0,2.757,2.243,5,5,5h14c2.757,0,5-2.243,5-5V5c0-2.757-2.243-5-5-5Zm-1.231,6.641l-4.466,5.359,4.466,5.359c.354.425.296,1.056-.128,1.409-.188.155-.414.231-.64.231-.287,0-.571-.122-.77-.359l-4.231-5.078-4.231,5.078c-.198.237-.482.359-.77.359-.226,0-.452-.076-.64-.231-.424-.354-.481-.984-.128-1.409l4.466-5.359-4.466-5.359c-.354-.425-.296-1.056.128-1.409.426-.353,1.056-.296,1.409.128l4.231,5.078,4.231-5.078c.354-.424.983-.48,1.409-.128.424.354.481.984.128,1.409Z"/></svg>`; 23 } else if (key?.toString() === 'warning') { 24 return `<svg fill="currentColor" width="28px" height="28px" viewBox="0 0 52 52" xmlns="http://www.w3.org/2000/svg"><path d="m51.4 42.5l-22.9-37c-1.2-2-3.8-2-5 0l-22.9 37c-1.4 2.3 0 5.5 2.5 5.5h45.8c2.5 0 4-3.2 2.5-5.5z m-25.4-2.5c-1.7 0-3-1.3-3-3s1.3-3 3-3 3 1.3 3 3-1.3 3-3 3z m3-9c0 0.6-0.4 1-1 1h-4c-0.6 0-1-0.4-1-1v-13c0-0.6 0.4-1 1-1h4c0.6 0 1 0.4 1 1v13z"></path></svg>`; 25 } else if (key?.toString() === 'close') { 26 return `<svg width="14px" height="14px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z" fill="currentColor"/></svg>`; 27 } else { 28 return `<svg fill="currentColor" width="28px" height="28px" viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg"> 29 <path d="M960 0c530.193 0 960 429.807 960 960s-429.807 960-960 960S0 1490.193 0 960 429.807 0 960 0Zm223.797 707.147c-28.531-29.561-67.826-39.944-109.227-39.455-55.225.657-114.197 20.664-156.38 40.315-100.942 47.024-178.395 130.295-242.903 219.312-11.616 16.025-17.678 34.946 2.76 49.697 17.428 12.58 29.978 1.324 40.49-9.897l.69-.74c.801-.862 1.591-1.72 2.37-2.565 11.795-12.772 23.194-25.999 34.593-39.237l2.85-3.31 2.851-3.308c34.231-39.687 69.056-78.805 115.144-105.345 27.4-15.778 47.142 8.591 42.912 35.963-2.535 16.413-11.165 31.874-17.2 47.744-21.44 56.363-43.197 112.607-64.862 168.888-23.74 61.7-47.405 123.425-70.426 185.398l-2 5.38-1.998 5.375c-20.31 54.64-40.319 108.872-53.554 165.896-10.575 45.592-24.811 100.906-4.357 145.697 11.781 25.8 36.77 43.532 64.567 47.566 37.912 5.504 78.906 6.133 116.003-2.308 19.216-4.368 38.12-10.07 56.57-17.005 56.646-21.298 108.226-54.146 154.681-92.755 47.26-39.384 88.919-85.972 126.906-134.292 12.21-15.53 27.004-32.703 31.163-52.596 3.908-18.657-12.746-45.302-34.326-34.473-11.395 5.718-19.929 19.867-28.231 29.27-10.42 11.798-21.044 23.423-31.786 34.92-21.488 22.987-43.513 45.463-65.634 67.831-13.54 13.692-30.37 25.263-47.662 33.763-21.59 10.609-38.785-1.157-36.448-25.064 2.144-21.954 7.515-44.145 15.046-64.926 30.306-83.675 61.19-167.135 91.834-250.686 19.157-52.214 38.217-104.461 56.999-156.816 17.554-48.928 32.514-97.463 38.834-149.3 4.357-35.71-4.9-72.647-30.269-98.937Zm63.72-401.498c-91.342-35.538-200.232 25.112-218.574 121.757-13.25 69.784 13.336 131.23 67.998 157.155 105.765 50.16 232.284-29.954 232.29-147.084.005-64.997-28.612-111.165-81.715-131.828Z" fill-rule="evenodd"/> 30 </svg>`; 31 } 32 } 33 34 // =============================== 35 // ToastMagic Class Definition 36 // =============================== 37 if (typeof window.ToastMagic === "undefined") { 38 window.ToastMagic = class ToastMagic { 39 constructor() { 40 this.setupConfig(); 41 this.initToastContainer(); 42 } 43 44 setupConfig() { 45 const config = window.toastMagicConfig || {}; 46 this.toastMagicPosition = config.positionClass || "toast-top-end"; 47 this.toastMagicCloseButton = config.closeButton || false; 48 this.toastMagicTheme = config.theme || "default"; 49 } 50 51 initToastContainer() { 52 this.toastContainer = document.querySelector(".toast-container"); 53 54 if (!this.toastContainer) { 55 this.toastContainer = document.createElement("div"); 56 this.toastContainer.classList.add("toast-container"); 57 document.body.appendChild(this.toastContainer); 58 } 59 60 const classList = `toast-container ${this.toastMagicPosition} theme-${this.toastMagicTheme}`; 61 if (this.toastContainer.className !== classList) { 62 this.toastContainer.className = classList; 63 } 64 } 65 66 show({ type, heading, description = "", showCloseBtn = this.toastMagicCloseButton, customBtnText = "", customBtnLink = "" }) { 67 this.setupConfig(); 68 this.initToastContainer(); 69 70 let toastClass, toastClassBasic; 71 switch (type) { 72 case "success": 73 toastClass = "toast-success"; 74 toastClassBasic = "success"; 75 break; 76 case "error": 77 toastClass = "toast-danger"; 78 toastClassBasic = "danger"; 79 break; 80 case "warning": 81 toastClass = "toast-warning"; 82 toastClassBasic = "warning"; 83 break; 84 case "info": 85 default: 86 toastClass = "toast-info"; 87 toastClassBasic = "info"; 88 } 89 90 const toast = document.createElement("div"); 91 toast.classList.add("toast-item", toastClass); 92 toast.setAttribute("role", "alert"); 93 toast.setAttribute("aria-live", "assertive"); 94 toast.setAttribute("aria-atomic", "true"); 95 96 toast.innerHTML = ` 97 <div class="theme-ios-toast-item-border"></div> 98 <div class="position-relative"> 99 <div class="toast-item-content-center"> 100 <div class="toast-body">
101 <span class="toast-body-icon-container toast-text-${toastClassBasic}"> 102 ${getToasterIcon(type)} 103 </span> 104 <div class="toast-body-container"> 105 ${heading ? `<div class="toast-body-title"><h4>${heading}</h4></div>` : ''} 106 ${description ? `<p class="fs-12">${description}</p>` : ''} 107 </div> 108 </div> 109 <div class="toast-body-end"> 110 ${showCloseBtn ? `<button type="button" class="toast-close-btn">${getToasterIcon('close')}</button>` : ""} 111 ${customBtnText && customBtnLink ? `<a href="${customBtnLink}" class="toast-custom-btn toast-btn-bg-${toastClassBasic}">${customBtnText}</a>` : ""} 112 </div> 113 </div> 114 </div>`; 115 116 const cfg = window.toastMagicConfig || {}; 117 const toastMagicPosition = cfg.positionClass || "toast-top-end"; 118 const toastMagicShowDuration = cfg?.showDuration || 100; 119 const toastMagicTimeOut = cfg?.timeOut || 5000; 120 121 if ( 122 toastMagicPosition === 'toast-bottom-end' || 123 toastMagicPosition === 'toast-bottom-start' || 124 toastMagicPosition === 'toast-top-center' 125 ) { 126 this.toastContainer.append(toast); 127 } else { 128 this.toastContainer.prepend(toast); 129 } 130 131 setTimeout(() => toast.classList.add("show"), toastMagicShowDuration); 132 setTimeout(() => closeToastMagicItem(toast), toastMagicTimeOut); 133 } 134 135 success(...args) { 136 this.show({ type: "success", ...this._parseArgs(args) }); 137 } 138 error(...args) { 139 this.show({ type: "error", ...this._parseArgs(args) }); 140 } 141 warning(...args) { 142 this.show({ type: "warning", ...this._parseArgs(args) }); 143 } 144 info(...args) { 145 this.show({ type: "info", ...this._parseArgs(args) }); 146 } 147 148 _parseArgs(args) { 149 const [heading = "", description = "", showCloseBtn = false, customBtnText = "", customBtnLink = ""] = args; 150 return { heading, description, showCloseBtn, customBtnText, customBtnLink }; 151 } 152 }; 153 } 154 155 // =============================== 156 // Initialize Instance Once 157 // =============================== 158 if (typeof window.toastMagic === "undefined") { 159 window.toastMagic = new window.ToastMagic(); 160 } 161 162 // =============================== 163 // DOM Ready: Setup Container + Events 164 // =============================== 165 document.addEventListener("DOMContentLoaded", function () { 166 const config = window.toastMagicConfig || {}; 167 const toastMagicPosition = config.positionClass || "toast-top-end"; 168 169 if (!document.querySelector(".toast-container")) { 170 document.body.insertAdjacentHTML( 171 "afterbegin", 172 `<div><div class="toast-container ${toastMagicPosition}"></div></div>` 173 ); 174 } 175 176 // Listen for toast trigger buttons 177 document.body.addEventListener("click", function (event) { 178 const btn = event.target.closest("[data-toast-type]"); 179 if (!btn) return; 180 181 const type = btn.getAttribute("data-toast-type"); 182 const heading = btn.getAttribute("data-toast-heading") || "Notification"; 183 const description = btn.getAttribute("data-toast-description") || ""; 184 const showCloseBtn = btn.hasAttribute("data-toast-close-btn"); 185 const customBtnText = btn.getAttribute("data-toast-btn-text") || ""; 186 const customBtnLink = btn.getAttribute("data-toast-btn-link") || ""; 187 188 if (window.toastMagic[type]) { 189 window.toastMagic[type](heading, description, showCloseBtn, customBtnText, customBtnLink); 190 } else { 191 window.toastMagic.info(heading, description, showCloseBtn, customBtnText, customBtnLink); 192 } 193 }); 194 195 // Listen for toast close buttons 196 document.body.addEventListener("click", function (event) { 197 const closeBtn = event.target.closest(".toast-close-btn"); 198 if (closeBtn) { 199 const toast = closeBtn.closest(".toast-item"); 200 if (toast) closeToastMagicItem(toast); 201 } 202 }); 203 }); 204})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.