-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (83 loc) · 2.85 KB
/
Copy pathscript.js
File metadata and controls
97 lines (83 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
document.documentElement.classList.add("js");
const menuToggle = document.querySelector("[data-menu-toggle]");
const navigation = document.querySelector("[data-navigation]");
const menuLabel = menuToggle?.querySelector(".sr-only");
if (menuToggle && navigation) {
const closeNavigation = ({ returnFocus = false } = {}) => {
menuToggle.setAttribute("aria-expanded", "false");
if (menuLabel) menuLabel.textContent = "Open navigation";
navigation.classList.remove("is-open");
if (returnFocus) menuToggle.focus();
};
menuToggle.addEventListener("click", () => {
const isOpen = menuToggle.getAttribute("aria-expanded") === "true";
if (isOpen) {
closeNavigation();
} else {
menuToggle.setAttribute("aria-expanded", "true");
if (menuLabel) menuLabel.textContent = "Close navigation";
navigation.classList.add("is-open");
}
});
navigation.addEventListener("click", (event) => {
if (event.target instanceof HTMLAnchorElement) {
closeNavigation();
}
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape" && menuToggle.getAttribute("aria-expanded") === "true") {
closeNavigation({ returnFocus: true });
}
});
window.addEventListener("resize", () => {
if (window.innerWidth > 920 && menuToggle.getAttribute("aria-expanded") === "true") {
closeNavigation();
}
});
}
const timeNode = document.querySelector("[data-local-time]");
const yearNodes = document.querySelectorAll("[data-current-year]");
function updateClock() {
const now = new Date();
if (timeNode) {
timeNode.textContent = new Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "2-digit",
}).format(now);
}
yearNodes.forEach((node) => {
node.textContent = String(now.getFullYear());
});
}
updateClock();
window.setInterval(updateClock, 30_000);
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
const revealNodes = document.querySelectorAll(".reveal");
if (reduceMotion.matches || !("IntersectionObserver" in window)) {
revealNodes.forEach((node) => node.classList.add("is-visible"));
} else {
const revealObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.14 },
);
revealNodes.forEach((node) => revealObserver.observe(node));
window.setTimeout(() => {
revealNodes.forEach((node) => node.classList.add("is-visible"));
}, 900);
}
const faqItems = document.querySelectorAll(".faq-list details");
faqItems.forEach((detail) => {
detail.addEventListener("toggle", () => {
if (!detail.open) return;
faqItems.forEach((other) => {
if (other !== detail) other.open = false;
});
});
});