<div class="bux-buckeye-alert__wrapper" role="region" aria-labelledby="buckeye-alert-title" hidden>
<div id="bux-buckeye-alert" class="bux-buckeye-alert" aria-label="Buckeye Alert" aria-live="polite" data-bux-alert-url=https://www.osu.edu/feeds/alert-test/feed.rss role="status" hidden>
</div>
</div>
{#
Buckeye Alert
Available variables:
- data_bux_alert_url: Attribute containing the Buckeye Alert RSS feed URL.
#}
<div class="bux-buckeye-alert__wrapper" role="region" aria-labelledby="buckeye-alert-title" hidden>
<div
id="bux-buckeye-alert"
class="bux-buckeye-alert"
aria-label="Buckeye Alert"
aria-live="polite"
data-bux-alert-url={{ data_bux_alert_url|default("https://www.osu.edu/feeds/emergency-alert.rss") }}
role="status"
hidden>
</div>
</div>
site_name_prefix: Office of
site_name: Learning Relations Excellence
site_slogan: Additional text or site slogan
address_1: 100 Building Name
address_2: 1 Oval Mall
city: Columbus
state: OH
zip: '43210'
contact_email: email@osu.edu
contact_phone: 614-292-OHIO
contact_tty: 614-688-8605
data_bux_alert_url: https://www.osu.edu/feeds/alert-test/feed.rss
.bux-buckeye-alert {
background-color: $scarlet;
padding: $sp-16 $sp-12;
h2 {
@include visually-hidden;
}
a {
@include link-base("scarlet", "no");
}
p {
color: $white;
font-family: $sans;
&:last-child {
margin-bottom: 0;
}
}
.bux-buckeye-alert-container {
display: flex;
.bux-buckeye-alert-container__icon {
line-height: 1;
margin-right: $sp-16;
&:after {
content: "\f623";
font-family: $icon;
font-size: $ts-md;
color: $white;
}
}
}
}
{
class BuckeyeAlert {
private readonly wrapper: Element;
private readonly url: string;
constructor(private readonly element: HTMLElement, private readonly settings: BuckeyeAlertSettings = {}) {
const dataUrl = this.element.dataset.buxAlertUrl;
this.url = settings.url || dataUrl || "https://www.osu.edu/feeds/emergency-alert.rss";
if (!this.url) {
throw new Error("BuckeyeAlert: No URL provided in settings or data-bux-alert-url attribute.");
}
this.wrapper = this.element.closest('.bux-buckeye-alert__wrapper') as HTMLElement;
this.element.setAttribute("hidden", "");
if (this.wrapper) {
this.wrapper.setAttribute("hidden", "");
}
}
initialize() {
fetch(this.url)
.then((response) => response.text())
.then((xmlString) => new DOMParser().parseFromString(xmlString, "text/xml"))
.then((data) => {
const alerts = data.querySelectorAll("item");
if (alerts.length > 0) {
this.buildAlerts(alerts);
this.displayAlerts();
}
})
.catch((error) => {
console.error("Error fetching Buckeye Alerts:", error);
});
}
static start() {
const alertElements = document.querySelectorAll("#bux-buckeye-alert");
for (const element of alertElements) {
new BuckeyeAlert(element as HTMLElement).initialize();
}
}
buildAlerts(alerts: NodeListOf<Element>) {
const container = document.createElement("div");
const icon = document.createElement("div");
const heading = document.createElement("h2");
container.classList.add("bux-buckeye-alert-container");
icon.classList.add("bux-buckeye-alert-container__icon");
container.append(icon);
container.append(heading);
heading.id = "buckeye-alert-title";
heading.textContent = "Buckeye Alert Emergency Message";
for (const alert of alerts) {
const description = alert.children[2];
const {textContent: message} = description;
container.innerHTML += message;
}
this.element.append(container);
}
displayAlerts() {
const wrapper = this.element.parentElement;
if (!wrapper) {
return;
}
this.element.removeAttribute("hidden");
wrapper.removeAttribute("hidden");
}
}
BuckeyeAlert.start();
}