128 lines
4.0 KiB
JavaScript
128 lines
4.0 KiB
JavaScript
"use strict";
|
|
|
|
document.documentElement.classList.replace("no-js", "js");
|
|
|
|
const QUICK_EXIT_URL = "https://www.google.com/";
|
|
const QUICK_EXIT_KEY = "quick-exit";
|
|
const STAGING_HOST = "whispersoflhj.cosmicallycreative.com";
|
|
const MOBILE_NAV_QUERY = window.matchMedia("(max-width: 88em)");
|
|
|
|
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();
|
|
});
|
|
});
|
|
|
|
if (window.location.hostname === STAGING_HOST) {
|
|
document.body.classList.add("client-preview");
|
|
document.querySelectorAll(".announcement-message").forEach((message) => {
|
|
message.textContent = "Client Preview";
|
|
});
|
|
}
|
|
|
|
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);
|
|
});
|
|
});
|