-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
106 lines (89 loc) · 2.92 KB
/
Copy pathscript.js
File metadata and controls
106 lines (89 loc) · 2.92 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
106
const CONTACTS = {
telegramHandle: "@crypto_recon",
telegramUrl: "https://t.me/crypto_recon"
};
const contactBindings = {
"telegram-handle": CONTACTS.telegramHandle,
"telegram-link": CONTACTS.telegramUrl
};
const reducedMotionQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
function syncMotionPreference() {
document.documentElement.classList.toggle("reduce-motion", reducedMotionQuery.matches);
}
function setupInitialScroll() {
if ("scrollRestoration" in history) {
history.scrollRestoration = "manual";
}
const resetScroll = () => {
if (!window.location.hash) {
window.scrollTo(0, 0);
}
};
resetScroll();
window.addEventListener("pageshow", resetScroll);
window.addEventListener("load", resetScroll);
}
function applyContactBindings() {
Object.entries(contactBindings).forEach(([key, value]) => {
document.querySelectorAll(`[data-contact="${key}"]`).forEach((node) => {
if (key.endsWith("-link")) {
node.setAttribute("href", value);
} else {
node.textContent = value;
}
});
});
}
function setupHeaderState() {
const header = document.querySelector(".site-header");
if (!header) return;
const syncHeader = () => {
header.classList.toggle("is-scrolled", window.scrollY > 18);
};
syncHeader();
window.addEventListener("scroll", syncHeader, { passive: true });
}
function setupYear() {
const year = document.getElementById("year");
if (year) {
year.textContent = String(new Date().getFullYear());
}
}
function setupMobileMenu() {
const btn = document.getElementById("mobile-menu-btn");
const menu = document.getElementById("mobile-menu");
const bar1 = document.getElementById("bar1");
const bar2 = document.getElementById("bar2");
const bar3 = document.getElementById("bar3");
if (!btn || !menu) return;
btn.addEventListener("click", () => {
const isOpen = !menu.classList.contains("hidden");
menu.classList.toggle("hidden", isOpen);
menu.classList.toggle("flex", !isOpen);
bar1.style.transform = isOpen ? "" : "rotate(45deg) translate(4px, 4px)";
bar2.style.opacity = isOpen ? "" : "0";
bar3.style.transform = isOpen ? "" : "rotate(-45deg) translate(4px, -4px)";
});
menu.querySelectorAll("a").forEach((link) => {
link.addEventListener("click", () => {
menu.classList.add("hidden");
menu.classList.remove("flex");
bar1.style.transform = "";
bar2.style.opacity = "";
bar3.style.transform = "";
});
});
}
document.addEventListener("DOMContentLoaded", () => {
syncMotionPreference();
if (typeof reducedMotionQuery.addEventListener === "function") {
reducedMotionQuery.addEventListener("change", syncMotionPreference);
} else if (typeof reducedMotionQuery.addListener === "function") {
reducedMotionQuery.addListener(syncMotionPreference);
}
setupInitialScroll();
applyContactBindings();
setupHeaderState();
setupYear();
setupMobileMenu();
});