-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (64 loc) · 2.27 KB
/
Copy pathscript.js
File metadata and controls
71 lines (64 loc) · 2.27 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
// Copy citation to clipboard
const copyButton = document.querySelector(".copy-button");
if (copyButton) {
copyButton.addEventListener("click", async () => {
const targetId = copyButton.dataset.copyTarget;
const target = document.getElementById(targetId);
if (!target) return;
const text = target.innerText.trim();
try {
await navigator.clipboard.writeText(text);
copyButton.textContent = "Copied";
window.setTimeout(() => {
copyButton.textContent = "Copy";
}, 1400);
} catch {
copyButton.textContent = "Select text";
}
});
}
// Scroll-spy: highlight the nav link for the section currently in view
const navLinks = Array.from(document.querySelectorAll(".navlinks a"));
const linkBySection = new Map();
const watchedSections = [];
navLinks.forEach((link) => {
const id = link.getAttribute("href");
if (!id || !id.startsWith("#")) return;
const section = document.querySelector(id);
if (!section) return;
linkBySection.set(section, link);
watchedSections.push(section);
});
if (watchedSections.length && "IntersectionObserver" in window) {
const spy = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
navLinks.forEach((l) => l.classList.remove("is-active"));
const active = linkBySection.get(entry.target);
if (active) active.classList.add("is-active");
});
},
{ rootMargin: "-45% 0px -50% 0px", threshold: 0 }
);
watchedSections.forEach((section) => spy.observe(section));
}
// Subtle reveal-on-scroll for sections and figures
const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const revealTargets = document.querySelectorAll(
".section, .hero-overview, .figure-card, .hero-stats > div"
);
if (!prefersReduced && "IntersectionObserver" in window) {
revealTargets.forEach((el) => el.classList.add("reveal"));
const revealer = new IntersectionObserver(
(entries, obs) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add("is-visible");
obs.unobserve(entry.target);
});
},
{ rootMargin: "0px 0px -10% 0px", threshold: 0.08 }
);
revealTargets.forEach((el) => revealer.observe(el));
}