-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (76 loc) · 2.61 KB
/
Copy pathscript.js
File metadata and controls
92 lines (76 loc) · 2.61 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
const menuButton = document.querySelector(".menu-toggle");
const siteNav = document.querySelector(".site-nav");
if (menuButton && siteNav) {
const closeMenu = () => {
siteNav.classList.remove("is-open");
document.body.classList.remove("menu-open");
menuButton.setAttribute("aria-expanded", "false");
menuButton.setAttribute("aria-label", "Open navigation menu");
};
menuButton.addEventListener("click", () => {
const isOpen = siteNav.classList.toggle("is-open");
document.body.classList.toggle("menu-open", isOpen);
menuButton.setAttribute("aria-expanded", String(isOpen));
menuButton.setAttribute("aria-label", isOpen ? "Close navigation menu" : "Open navigation menu");
});
siteNav.addEventListener("click", (event) => {
if (event.target instanceof HTMLAnchorElement) {
closeMenu();
}
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeMenu();
}
});
}
const tabs = Array.from(document.querySelectorAll(".schedule-tab"));
const panels = Array.from(document.querySelectorAll(".schedule-panel"));
const stickyCta = document.querySelector(".sticky-cta");
const activateTab = (tab) => {
tabs.forEach((candidate) => {
const isActive = candidate === tab;
candidate.classList.toggle("is-active", isActive);
candidate.setAttribute("aria-selected", String(isActive));
candidate.tabIndex = isActive ? 0 : -1;
});
panels.forEach((panel) => {
const isActive = panel.id === tab.getAttribute("aria-controls");
panel.classList.toggle("is-active", isActive);
panel.hidden = !isActive;
});
};
tabs.forEach((tab, index) => {
tab.addEventListener("click", () => activateTab(tab));
tab.addEventListener("keydown", (event) => {
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) {
return;
}
event.preventDefault();
let nextIndex = index;
if (event.key === "ArrowRight") {
nextIndex = (index + 1) % tabs.length;
}
if (event.key === "ArrowLeft") {
nextIndex = (index - 1 + tabs.length) % tabs.length;
}
if (event.key === "Home") {
nextIndex = 0;
}
if (event.key === "End") {
nextIndex = tabs.length - 1;
}
tabs[nextIndex].focus();
activateTab(tabs[nextIndex]);
});
});
if (stickyCta) {
const syncStickyCta = () => {
const isVisible = window.scrollY > 520;
stickyCta.classList.toggle("is-visible", isVisible);
stickyCta.setAttribute("aria-hidden", String(!isVisible));
stickyCta.tabIndex = isVisible ? 0 : -1;
};
syncStickyCta();
window.addEventListener("scroll", syncStickyCta, { passive: true });
}