1var __defProp = Object.defineProperty; 2var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 }); 3import { setCookie, getCookie, loadJS } from "../lib/unl-utility.js?v=6.1.6"; 4import { l as loadStyleSheet } from "../chunks/chunk.dcf-utility.js?v=6.1.6"; 5const unlAlertCssUrl = "/wdn/templates_6.1/css/components-js/_unl-alert.css?v=6.1.6"; 6class UNLAlert { 7 static { 8 __name(this, "UNLAlert"); 9 } 10 alertDataUrl; 11 alertDataActiveIDs = []; 12 serverCallTimeoutID; 13 closedAlertCookieName = "unlAlertsC"; 14 alertDataReceivedCookieName = "unlAlertsData"; 15 activeAlertCookieName = "unlAlertsA"; 16 serverCallExecutionDelay = 3e4; 17 // Delay (in milliseconds) before executing the checkIfServerCallIsNeeded function 18 serverCallExecutionDelayTwo = 31e3; 19 // Secondary delay (in milliseconds) before executing the checkIfServerCallIsNeeded function 20 alertDataReceivedCookieMaxAge = 30; 21 // Maximum age (in seconds) for the alertDataReceived cookie 22 closedAlertCookieMaxAge = 3600; 23 // Maximum age (in seconds) for the alertDataReceived cookie 24 constructor() { 25 loadStyleSheet(unlAlertCssUrl), this.alertDataUrl = "https://alert.unl.edu/json/unlcap.js?v=6.1.6", window.unlAlerts = window.unlAlerts || {}, window.unlAlerts.data = window.unlAlerts.data || {}, this.#fetchAlertData(), document.dispatchEvent( 26 new CustomEvent(UNLAlert.events("UNLAlertReady"), { 27 detail: { 28 classInstance: this 29 } 30 }) 31 ); 32 } 33 // The names of the events to be used easily 34 static events(name) { 35 const events = { 36 UNLAlertReady: "UNLAlertReady" 37 }; 38 return Object.freeze(events), name in events ? events[name] : void 0; 39 } 40 // Sets a cookie to indicate that there is an active alert 41 #setActiveAlertCookie = /* @__PURE__ */ __name((flag) => { 42 let value = 1, time = 60; 43 flag === !1 && (value = "", time = -1), setCookie(this.activeAlertCookieName, value, time); 44 }, "#setActiveAlertCookie"); 45 // Sets a cookie to indicate that there is an acknowledged alert 46 #setClosedAlertCookie(alertDataActiveID) { 47 const closedAlertCookieValue = this.#getClosedAlertCookie(); 48 closedAlertCookieValue.indexOf(alertDataActiveID) === -1 && (closedAlertCookieValue.push(alertDataActiveID), setCookie( 49 this.closedAlertCookieName, 50 closedAlertCookieValue.join(","), 51 this.closedAlertCookieMaxAge 52 )); 53 } 54 #getClosedAlertCookie() { 55 const cookie = getCookie(this.closedAlertCookieName); 56 return cookie ? cookie.split(",") : []; 57 } 58 #acknowledgeAlert(alertDataActiveID) { 59 this.#setClosedAlertCookie(alertDataActiveID); 60 } 61 #isAlertAcknowledged(alertDataID) { 62 return this.#getClosedAlertCookie().indexOf(alertDataID) !== -1; 63 } 64 #checkIfFetchCallNeeded = /* @__PURE__ */ __name(() => { 65 this.#fetchAlertData(); 66 }, "#checkIfFetchCallNeeded"); 67 #toggleAlert() { 68 const alert = document.getElementById("unlalert"), alertIconClose = document.getElementById("unlalert_icon_close"), alertIconWarning = document.getElementById("unlalert_icon_warning"), alertAction = document.getElementById("unlalert_action"); 69 if (alert.classList.contains("show")) { 70 alert.classList.remove("show"); 71 const body = alert.closest("body"); 72 body && body.classList.remove("unlalert-shown"), alertIconClose.setAttribute("hidden", "true"), alertIconWarning.removeAttribute("hidden"), alertAction.classList.remove("dcf-sr-only"), alertAction.classList.add("dcf-ml-2", "dcf-txt-sm"), alertAction.textContent = "Show emergency alert"; 73 for (let counter = 0; counter < this.alertDataActiveIDs.length; counter++) 74 this.#acknowledgeAlert(this.alertDataActiveIDs[counter]); 75 } else { 76 if (alert) { 77 alert.classList.add("show"); 78 const body = alert.closest("body"); 79 body && body.classList.add("unlalert-shown"); 80 } 81 alertIconWarning && alertIconWarning.setAttribute("hidden", "true"), alertIconClose && alertIconClose.removeAttribute("hidden"), alertAction && (alertAction.classList.remove("dcf-ml-2", "dcf-txt-sm"), alertAction.classList.add("dcf-sr-only"), alertAction.textContent = "Hide emergency alert"); 82 } 83 } 84 #alertUser(alertData) { 85 this.#setActiveAlertCookie(!0), this.alertDataActiveIDs = []; 86 let unlAlertDivWrapper = document.getElementById("unlalert"), alertToggle = document.getElementById("unlalert_toggle"), unlAlertContent, containsExtreme = !1, info = alertData.info, effectiveDate = "", web, alertContentHTML, alertAcknowledgmentStatus = !0; 87 const alertDataID = alertData.identifier || +/* @__PURE__ */ new Date(), dcfHeaderDiv = document.getElementById("dcf-header"), alertIconSvg = `<svg id="unlalert" class="dcf-h-4 dcf-w-4 dcf-fill-current" viewBox="0 0 24 24" height="16" width="16" focusable="false" aria-hidden="true"> 88 <g id="unlalert_icon_close"> 89 <path d="M13.4 12 23.7 1.7c.4-.4.4-1 0-1.4s-1-.4-1.4 0L12 10.6 1.7.3C1.3-.1.7-.1.3.3s-.4 1 0 1.4L10.6 12 .3 22.3c-.4.4-.4 1 0 1.4.2.2.4.3.7.3s.5-.1.7-.3L12 13.4l10.3 10.3c.2.2.5.3.7.3s.5-.1.7-.3c.4-.4.4-1 0-1.4L13.4 12z"> 90 </path> 91 </g> 92 <g id="unlalert_icon_warning" hidden> 93 <path 94 d="M12 17.3c-.6 0-1-.4-1-1V8.7c0-.6.4-1 1-1s1 .4 1 1v7.7c0 .5-.4.9-1 .9z"> 95 </path> 96 <path 97 d="M23 24H1c-.3 0-.7-.2-.9-.5s-.2-.7 0-1l11-22c.3-.7 1.5-.7 1.8 0l11 22c.2.3.1.7 0 1s-.6.5-.9.5zM2.6 22h18.8L12 3.2 2.6 22z"> 98 </path> 99 <path 100 d="M12 21c-.8 0-1.5-.7-1.5-1.5S11.2 18 12 18s1.5.7 1.5 1.5S12.8 21 12 21z"> 101 </path> 102 </g> 103 <path fill="none" d="M0 0h24v24H0z"> 104 </path> 105 </svg>`; 106 info instanceof Array || (info = [info]); 107 for (let counter = 0; counter < info.length; counter++) 108 info[counter].severity === "Extreme" && (containsExtreme = !0); 109 if (containsExtreme) { 110 this.alertDataActiveIDs.push(alertDataID), alertAcknowledgmentStatus = this.#isAlertAcknowledged(alertDataID), effectiveDate = new Date(alertData.sent).toLocaleStr
110ing(); 111 for (let counter = 0; counter < info.length; counter++) { 112 if (unlAlertDivWrapper) 113 counter === 0 && (unlAlertContent = document.getElementById("unlalert_content"), unlAlertContent && (unlAlertContent.innerHTML = "")); 114 else { 115 unlAlertDivWrapper = document.createElement("div"), unlAlertDivWrapper.setAttribute("id", "unlalert"), unlAlertDivWrapper.className = "dcf-bleed dcf-z-1", unlAlertDivWrapper.setAttribute("role", "alert"), unlAlertDivWrapper.style.position = "absolute", unlAlertDivWrapper.style.top = "-1000px", dcfHeaderDiv.parentNode.insertBefore(unlAlertDivWrapper, dcfHeaderDiv), unlAlertContent = document.createElement("div"), unlAlertContent.className = "dcf-relative dcf-col-gap-vw dcf-row-gap-6", unlAlertContent.setAttribute("id", "unlalert_content"); 116 const unlAlertInnerDivWrapper = document.createElement("div"); 117 unlAlertInnerDivWrapper.className = "dcf-wrapper", unlAlertInnerDivWrapper.appendChild(unlAlertContent), unlAlertDivWrapper.appendChild(unlAlertInnerDivWrapper); 118 } 119 web = info[counter].web || "https://www.unl.edu/", alertContentHTML = `<div class="unlalert-info"><header><h2 class="unlalert-heading dcf-mb-2 dcf-txt-2xs dcf-regular dcf-lh-3 dcf-uppercase unl-ls-2">Emergency alert</h2><h3 class="unlalert-headline dcf-mt-0 dcf-txt-h4"> 120 ${info[counter].headline} 121 </h3></header><p class="unlalert-desc dcf-mb-0 dcf-txt-xs"> 122 ${info[counter].description} 123 </p>`, info[counter].instruction && (alertContentHTML += `<p class="unlalert-desc dcf-mt-2 dcf-mb-0 dcf-txt-xs"> 124 ${info[counter].instruction} 125 </p>`), alertContentHTML += `</div><footer class="unlalert-meta dcf-d-grid dcf-col-gap-vw dcf-row-gap-5 dcf-txt-2xs"><div class="unlalert-datetime"><span class="unlalert-heading dcf-d-block dcf-mb-1 dcf-lh-3 dcf-uppercase unl-ls-2">Issued </span> 126 ${effectiveDate} 127 </div><div class="unlalert-link"><span class="unlalert-heading dcf-d-block dcf-mb-1 dcf-lh-3 dcf-uppercase unl-ls-2">Additional info (if available)<span class="dcf-sr-only">: </span></span> 128 <a href="${web}">${web}</a> 129 </div></footer>`, unlAlertContent.insertAdjacentHTML("beforeend", alertContentHTML); 130 } 131 if (!alertToggle) { 132 const alertToggleSpan = document.createElement("span"); 133 alertToggleSpan.setAttribute("id", "unlalert_action"), alertToggleSpan.className = "dcf-ml-2 dcf-txt-sm", alertToggleSpan.textContent = "Show emergency alert", alertToggle = document.createElement("button"), alertToggle.className = "dcf-btn dcf-btn-tertiary dcf-txt-decor-none dcf-d-flex dcf-ai-center dcf-jc-center dcf-txt-base", alertToggle.setAttribute("id", "unlalert_toggle"), alertToggle.insertAdjacentHTML("beforeend", alertIconSvg), alertToggle.appendChild(alertToggleSpan); 134 const alertContentParent = unlAlertContent.parentElement; 135 alertContentParent && alertContentParent.appendChild(alertToggle), alertToggle.addEventListener("click", () => this.#toggleAlert()); 136 } 137 if (!alertAcknowledgmentStatus) 138 unlAlertDivWrapper.classList.contains("show") || alertToggle.click(); 139 else { 140 const alertIconClose = alertToggle.querySelector("#unlalert_icon_close"), alertIconWarning = alertToggle.querySelector("#unlalert_icon_warning"); 141 alertIconClose && alertIconClose.setAttribute("hidden", "true"), alertIconWarning && alertIconWarning.removeAttribute("hidden"); 142 } 143 } 144 } 145 #noAlert() { 146 this.#setActiveAlertCookie(!1); 147 const unlAlertDivWrapper = document.getElementById("unlalert"); 148 unlAlertDivWrapper && unlAlertDivWrapper.remove(); 149 } 150 async #fetchAlertData() { 151 try { 152 const dataURL = new URL(this.alertDataUrl); 153 dataURL.searchParams.set("cb", Date.now()), await loadJS(dataURL.toString()); 154 const unlAlertsData = window.unlAlerts.data; 155 unlAlertsData && unlAlertsData.alert && window.top === window && unlAlertsData.alert && unlAlertsData.alert.info ? this.#alertUser(unlAlertsData.alert) : this.#noAlert(), clearTimeout(this.serverCallTimeoutID), this.serverCallTimeoutID = setTimeout( 156 () => this.#checkIfFetchCallNeeded(), 157 this.serverCallExecutionDelayTwo 158 ); 159 } catch { 160 console.error("An unexpected error occurred while fetching the alert data."); 161 } 162 } 163} 164export { 165 UNLAlert as default 166}; 167//# sourceMappingURL=component.alert.js.map
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.