1(function (window, document) { 2 "use strict"; 3 4 var VALID_TYPES = ["success", "error", "warning", "info"]; 5 var DEFAULT_DURATIONS = { 6 success: 3600, 7 error: 5200, 8 warning: 4600, 9 info: 4000 10 }; 11 var ICONS = { 12 success: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="8" fill="currentColor"/><path d="m6.6 10.1 2.1 2.2 4.8-5" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>', 13 error: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="8" fill="currentColor"/><path d="m7.2 7.2 5.6 5.6m0-5.6-5.6 5.6" fill="none" stroke="#fff" stroke-width="1.7" stroke-linecap="round"/></svg>', 14 warning: '<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M10 2.3 18 16.8H2L10 2.3Z" fill="currentColor"/><path d="M10 6.6v5.1m0 2.5v.1" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg>', 15 info: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="8" fill="currentColor"/><path d="M10 8.7v5m0-8v.1" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg>' 16 }; 17 var CLOSE_ICON = '<svg viewBox="0 0 20 20" aria-hidden="true"><path d="m5 5 10 10M15 5 5 15" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>'; 18 var root = null; 19 var recentSignature = ""; 20 var recentAt = 0; 21 22 function isObject(value) { 23 return value && typeof value === "object" && !Array.isArray(value); 24 } 25 26 function normalizeType(value) { 27 var type = String(value || "success").toLowerCase(); 28 29 if (type === "danger" || type === "fail" || type === "failed") { 30 type = "error"; 31 } 32 33 return VALID_TYPES.indexOf(type) >= 0 ? type : "success"; 34 } 35 36 function messageText(value) { 37 if (value instanceof Error) { 38 return value.message || "Something went wrong."; 39 } 40 41 if (value == null) { 42 return ""; 43 } 44 45 if (typeof value === "object") { 46 return value.message ? String(value.message) : String(value); 47 } 48 49 return String(value); 50 } 51 52 function interpolate(message, args) { 53 var result = messageText(message); 54 55 (args || []).forEach(function (arg, index) { 56 var replacement = messageText(arg); 57 result = result.replace(new RegExp("\\{\\s*" + index + "\\s*\\}", "g"), function () { 58 return replacement; 59 }); 60 result = result.replace("{}", function () { 61 return replacement; 62 }); 63 result = result.replace("%s", function () { 64 return replacement; 65 }); 66 }); 67 68 return result; 69 } 70 71 function normalizeOptions(typeOrArgs, thirdArgument, fourthArgument) { 72 var type = "success"; 73 var args = []; 74 var options = {}; 75 76 if (Array.isArray(typeOrArgs)) { 77 args = typeOrArgs; 78 if (typeof thirdArgument === "string") type = thirdArgument; 79 if (typeof thirdArgument === "number") options.duration = thirdArgument; 80 if (isObject(thirdArgument)) options = Object.assign(options, thirdArgument); 81 if (isObject(fourthArgument)) options = Object.assign(options, fourthArgument); 82 } else if (typeof typeOrArgs === "string") { 83 type = typeOrArgs; 84 if (typeof thirdArgument === "number") options.duration = thirdArgument; 85 if (isObject(thirdArgument)) options = Object.assign(options, thirdArgument); 86 } else if (typeof typeOrArgs === "number") { 87 options.duration = typeOrArgs; 88 } else if (isObject(typeOrArgs)) { 89 options = Object.assign(options, typeOrArgs); 90 type = options.type || type; 91 args = Array.isArray(options.args) ? options.args : args; 92 } 93 94 return { 95 type: normalizeType(type), 96 args: args, 97 options: options 98 }; 99 } 100 101 function ensureRoot() { 102 if (root && root.isConnected) return root; 103 104 root = document.querySelector("[data-site-toast-region]"); 105 if (!root) { 106 root = document.createElement("div"); 107 root.className = "site-toast-region"; 108 root.setAttribute("data-site-toast-region", ""); 109 root.setAttribute("aria-live", "polite"); 110 root.setAttribute("aria-atomic", "false"); 111 (document.body || document.documentElement).appendChild(root); 112 } 113 114 if (document.body && document.querySelector(".mobile-bottom-nav")) { 115 document.body.classList.add("site-toast-has-bottom-nav"); 116 } 117 118 return root; 119 } 120 121 function closeToast(toast, immediate) { 122 if (!toast || toast.dataset.closing === "true") return; 123 124 toast.dataset.closing = "true"; 125 window.clearTimeout(toast._siteToastTimer); 126 127 if (immediate) { 128 toast.remove(); 129 return; 130 } 131 132 toast.classList.add("is-leaving"); 133 window.setTimeout(function () { 134 toast.remove(); 135 }, 190); 136 } 137 138 function scheduleClose(toast, duration) { 139 var remaining = duration; 140 var startedAt = Date.now(); 141 var running = false;
142 143 function start() { 144 if (running || !(remaining > 0) || toast.dataset.closing === "true") return; 145 running = true; 146 startedAt = Date.now(); 147 toast._siteToastTimer = window.setTimeout(function () { 148 running = false; 149 closeToast(toast); 150 }, remaining); 151 } 152 153 function pause() { 154 if (!running || !(remaining > 0)) return; 155 running = false; 156 window.clearTimeout(toast._siteToastTimer); 157 remaining = Math.max(0, remaining - (Date.now() - startedAt)); 158 } 159 160 toast.addEventListener("mouseenter", pause); 161 toast.addEventListener("mouseleave", start); 162 toast.addEventListener("focusin", pause); 163 toast.addEventListener("focusout", start); 164 start(); 165 } 166 167 function show(message, typeOrArgs, thirdArgument, fourthArgument) { 168 var normalized = normalizeOptions(typeOrArgs, thirdArgument, fourthArgument); 169 var type = normalized.type; 170 var options = normalized.options; 171 var text = interpolate(message, normalized.args); 172 var region = ensureRoot(); 173 var signature = type + ":" + text; 174 var now = Date.now(); 175 176 if (signature === recentSignature && now - recentAt < 500) { 177 for (var i = 0; i < region.children.length; i += 1) { 178 if (region.children[i].dataset.toastSignature === signature) { 179 return region.children[i]; 180 } 181 } 182 } 183 184 recentSignature = signature; 185 recentAt = now; 186 187 while (region.children.length >= 3) { 188 closeToast(region.firstElementChild, true); 189 } 190 191 var toast = document.createElement("div"); 192 var icon = document.createElement("span"); 193 var content = document.createElement("span"); 194 var close = document.createElement("button"); 195 var duration = Number(options.duration); 196 197 toast.className = "site-toast site-toast--" + type; 198 toast.dataset.toastSignature = signature; 199 toast.setAttribute("role", type === "error" ? "alert" : "status"); 200 201 icon.className = "site-toast__icon"; 202 icon.innerHTML = ICONS[type]; 203 204 content.className = "site-toast__message"; 205 content.textContent = text; 206 207 close.className = "site-toast__close"; 208 close.type = "button"; 209 close.setAttribute("aria-label", options.closeLabel || "Close notification"); 210 close.innerHTML = CLOSE_ICON; 211 close.addEventListener("click", function () { 212 closeToast(toast); 213 }); 214 215 toast.append(icon, content, close); 216 region.appendChild(toast); 217 218 if (!Number.isFinite(duration)) { 219 duration = DEFAULT_DURATIONS[type]; 220 } 221 if (duration > 0) { 222 scheduleClose(toast, duration); 223 } 224 225 return toast; 226 } 227 228 function legacyNoti(message, secondArgument, thirdArgument, fourthArgument) { 229 return show(message, secondArgument, thirdArgument, fourthArgument); 230 } 231 232 function installLegacyAlias() { 233 window.noti = legacyNoti; 234 } 235 236 function closeAll() { 237 var region = ensureRoot(); 238 Array.prototype.forEach.call(region.children, function (toast) { 239 closeToast(toast); 240 }); 241 } 242 243 window.siteToast = show; 244 window.SiteToast = { 245 show: show, 246 closeAll: closeAll 247 }; 248 249 installLegacyAlias(); 250 document.addEventListener("DOMContentLoaded", installLegacyAlias); 251 window.addEventListener("load", installLegacyAlias); 252 document.addEventListener("site:toast", function (event) { 253 var detail = event.detail || {}; 254 show(detail.message, detail.type || "success", detail.options || {}); 255 }); 256})(window, document);
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.