Files
whispers-of-lhj-site/script.js
T
Cursor AgentandCosmically Creative 1560aeccb2 feat: apply production QA fixes for contrast, brunch, and crawl files
Put the Benefit Brunch in the announcement and footer, add a sitemap and homepage JSON-LD, and raise text contrast, tap targets, and hero photo scrims. Compress drone.JPG and the community event photo without changing their paths.

Co-authored-by: Cosmically Creative <Cosmically-Creative@users.noreply.github.com>
2026-10-07 19:20:33 +00:00

179 lines
5.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
document.documentElement.classList.replace("no-js", "js");
const QUICK_EXIT_URL = "https://www.google.com/";
const QUICK_EXIT_KEY = "quick-exit";
const MOBILE_NAV_QUERY = window.matchMedia("(max-width: 88em)");
// Benefit Brunch stays up through Saturday, October 10, 2026, US Central time.
// endsAt is midnight at the start of Sunday (CDT, UTC−5).
// After that, the announcement comes down and /events/ sends visitors home.
// Keep this instant in sync with the events page head script and the .htaccess brunch rule.
const eventAnnouncement = {
label: "Benefit Brunch",
date: "Oct 10",
endsAt: "2026-10-11T05:00:00Z",
};
function eventIsActive() {
const endsAt = Date.parse(eventAnnouncement.endsAt);
return Number.isFinite(endsAt) && Date.now() < endsAt;
}
function navigationType() {
const navigation = performance.getEntriesByType("navigation")[0];
return navigation ? navigation.type : "";
}
function quickExit() {
try {
// Remember the exit for this tab so Back cannot reopen the site.
sessionStorage.setItem(QUICK_EXIT_KEY, "1");
} catch (error) {}
document.documentElement.hidden = true;
if (document.body) document.body.replaceChildren();
window.location.replace(QUICK_EXIT_URL);
}
try {
if (navigationType() === "back_forward" && sessionStorage.getItem(QUICK_EXIT_KEY) === "1") {
document.documentElement.hidden = true;
window.location.replace(QUICK_EXIT_URL);
}
} catch (error) {}
window.addEventListener("pageshow", (event) => {
if (!event.persisted) return;
try {
if (sessionStorage.getItem(QUICK_EXIT_KEY) !== "1") return;
} catch (error) {
return;
}
document.documentElement.hidden = true;
window.location.replace(QUICK_EXIT_URL);
});
document.querySelectorAll(".quick-exit").forEach((link) => {
link.addEventListener("click", (event) => {
event.preventDefault();
quickExit();
});
});
function directoryDepth() {
const path = window.location.pathname;
const directory = path.endsWith("/") ? path : path.slice(0, path.lastIndexOf("/") + 1);
return directory.split("/").filter(Boolean).length;
}
function isEventsPage() {
return /\/events\/(?:index\.html)?$/.test(window.location.pathname);
}
if (!eventIsActive() && isEventsPage()) {
document.documentElement.hidden = true;
const home = "../".repeat(directoryDepth());
window.location.replace(home || "./");
} else if (eventIsActive()) {
const href = `${"../".repeat(directoryDepth())}events/`;
document.querySelectorAll(".announcement-message").forEach((message) => {
let link = message.querySelector(".announcement-link");
if (!link) {
const date = document.createElement("span");
link = document.createElement("a");
link.className = "announcement-link";
link.href = href;
link.append(eventAnnouncement.label, " ");
date.className = "text-yellow";
date.textContent = eventAnnouncement.date;
link.append(date);
message.replaceChildren(link);
}
if (isEventsPage()) link.setAttribute("aria-current", "page");
message.closest(".announcement-bar")?.classList.add("announcement-bar--active");
});
} else {
document.querySelectorAll(".announcement-message").forEach((message) => {
message.replaceChildren();
message.closest(".announcement-bar")?.classList.remove("announcement-bar--active");
});
}
document.addEventListener("keydown", (event) => {
if (event.key !== "Escape") return;
event.preventDefault();
quickExit();
});
document.addEventListener("click", (event) => {
if (event.defaultPrevented || event.button !== 0) return;
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
const link = event.target.closest("a[href]");
if (!link || link.classList.contains("quick-exit")) return;
if (link.target && link.target !== "_self") return;
if (link.hasAttribute("download")) return;
let url;
try {
url = new URL(link.href);
} catch (error) {
return;
}
if (url.origin !== window.location.origin) return;
if (url.pathname === window.location.pathname && url.search === window.location.search && url.hash) return;
event.preventDefault();
window.location.replace(url.href);
});
document.querySelectorAll(".nav").forEach((nav) => {
const toggle = nav.querySelector(".mobile-nav-toggle");
const toggleLabel = toggle?.querySelector(".mobile-nav-toggle-label");
const navigationLinks = nav.querySelector(".nav-links");
const navigationActions = nav.querySelector(".btns");
if (!toggle || !toggleLabel || !navigationLinks || !navigationActions) return;
function setMenuState(isOpen) {
nav.classList.toggle("nav--open", isOpen);
document.body.classList.toggle("mobile-nav-open", isOpen);
toggle.setAttribute("aria-expanded", String(isOpen));
toggle.setAttribute("aria-label", isOpen ? "Close navigation" : "Open navigation");
toggleLabel.textContent = isOpen ? "Close" : "Menu";
}
toggle.addEventListener("click", () => {
setMenuState(!nav.classList.contains("nav--open"));
});
navigationLinks.addEventListener("click", (event) => {
if (event.target.closest("a")) setMenuState(false);
});
navigationActions.addEventListener("click", (event) => {
if (event.target.closest("a")) setMenuState(false);
});
document.addEventListener("click", (event) => {
if (nav.classList.contains("nav--open") && !nav.contains(event.target)) {
setMenuState(false);
}
});
MOBILE_NAV_QUERY.addEventListener("change", (event) => {
if (!event.matches) setMenuState(false);
});
});