-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
105 lines (83 loc) · 2.7 KB
/
main.js
File metadata and controls
105 lines (83 loc) · 2.7 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
98
99
100
101
102
103
104
105
// Wait until DOM is ready
document.addEventListener("DOMContentLoaded", () => {
/* =========================
Footer load + year
========================= */
fetch("footer.html")
.then(res => res.text())
.then(html => {
const footer = document.getElementById("site-footer");
if (footer) footer.innerHTML = html;
const yearEl = document.getElementById("year");
if (yearEl) yearEl.textContent = new Date().getFullYear();
});
/* =========================
Mobile nav
========================= */
const toggle = document.querySelector(".nav-toggle");
const mobileNav = document.getElementById("mobile-nav");
const closeBtn = document.querySelector(".mobile-nav__close");
function openNav(){
mobileNav?.classList.add("is-open");
mobileNav?.setAttribute("aria-hidden", "false");
toggle?.setAttribute("aria-expanded", "true");
document.body.classList.add("nav-open");
}
function closeNav(){
mobileNav?.classList.remove("is-open");
mobileNav?.setAttribute("aria-hidden", "true");
toggle?.setAttribute("aria-expanded", "false");
document.body.classList.remove("nav-open");
}
toggle?.addEventListener("click", (e) => {
e.stopPropagation();
openNav();
});
closeBtn?.addEventListener("click", closeNav);
mobileNav?.querySelectorAll("a").forEach(a =>
a.addEventListener("click", closeNav)
);
document.addEventListener("keydown", (e) => {
if(e.key === "Escape") closeNav();
});
document.addEventListener("click", (e) => {
if (!mobileNav?.classList.contains("is-open")) return;
const target = e.target;
if (!(target instanceof Node)) return;
const inside = mobileNav.contains(target);
const toggleClicked = toggle && toggle.contains(target);
if (!inside && !toggleClicked) closeNav();
});
/* =========================
Back to top
========================= */
const backToTop = document.getElementById("backToTop");
if (backToTop) {
window.addEventListener("scroll", () => {
backToTop.style.display =
window.scrollY > 300 ? "flex" : "none";
});
backToTop.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
}
});
/* =========================
Plot carousel scroll (GLOBAL)
========================= */
function scrollPlots(button, direction) {
const carousel = button.closest(".plot-carousel");
if (!carousel) return;
const container = carousel.querySelector(
".product-plot-strip, .product-plot-strip-wide"
);
if (!container) return;
const scrollAmount = container.clientWidth * 0.8;
container.scrollBy({
left: direction * scrollAmount,
behavior: "smooth"
});
}