Repository navigation
Expand file tree
/
Copy pathreveal.js
More file actions
100 lines (96 loc) · 3.88 KB
/
Copy pathreveal.js
File metadata and controls
100 lines (96 loc) · 3.88 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
// A restrained, one-time reveal for section-level content. The hero and
// navigation paint immediately; only content reached by scrolling moves.
(function () {
"use strict";
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const targets = document.querySelectorAll(
"main .band > *, main .model-evidence-links-top"
);
targets.forEach(function (el) { el.classList.add("scroll-reveal"); });
if (reduce || !("IntersectionObserver" in window)) {
targets.forEach(function (el) { el.classList.add("in-view"); });
return;
}
const io = new IntersectionObserver(
function (entries) {
entries.forEach(function (e) {
if (e.isIntersecting) {
e.target.classList.add("in-view");
io.unobserve(e.target);
}
});
},
{ threshold: 0.08, rootMargin: "0px 0px -7% 0px" }
);
targets.forEach(function (el) {
if (el.getBoundingClientRect().top < window.innerHeight * 0.92) {
el.classList.add("in-view", "reveal-initial");
} else if (el.offsetHeight > window.innerHeight * 0.7) {
// Tall blocks (long walkthroughs, scrollytelling wrappers) may never
// reach the 8% intersection threshold — show them without animation.
el.classList.add("in-view", "reveal-initial");
} else {
io.observe(el);
}
});
})();
// Keep sticky subnavs flush under the fixed header: expose the header's
// real height as --nav-h so sticky offsets never drift from it.
(function () {
"use strict";
var nav = document.querySelector("header.nav");
if (!nav) return;
function set() {
document.documentElement.style.setProperty(
"--nav-h", nav.getBoundingClientRect().height + "px"
);
}
window.addEventListener("resize", set, { passive: true });
window.addEventListener("load", set);
if (document.fonts && document.fonts.ready) document.fonts.ready.then(set);
set();
})();
/* A fragment that targets a <details> element scrolls to it but does not open
it — browsers auto-expand only when the fragment targets a DESCENDANT. Three
high-traffic links point at /models#score, where the id sits on the <details>
itself, so the primary "score a reform" journey landed on a closed summary
with the content hidden. Open it on load and on subsequent hash changes. */
(function () {
"use strict";
function openTargetedDetails() {
if (!location.hash || location.hash.length < 2) return;
var target;
try { target = document.querySelector(location.hash); } catch (e) { return; }
if (!target) return;
if (target.tagName === "DETAILS") target.open = true;
var parent = target.closest && target.closest("details");
if (parent) parent.open = true;
target.scrollIntoView({ block: "start" });
}
window.addEventListener("hashchange", openTargetedDetails);
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", openTargetedDetails);
} else {
openTargetedDetails();
}
})();
/* Copy-to-clipboard, shared. This handler was pasted verbatim into fifteen
pages and omitted from models/index.html, which renders a copy button in
#score — the target of fifteen links — that did nothing. One delegated
copy, so a page gets the behaviour by loading this file. */
(function () {
"use strict";
document.addEventListener("click", function (event) {
var button = event.target.closest("[data-copy]");
if (!button) return;
// /connect wraps its blocks in .code-window, so the code element is not
// a child of the button's parent there.
var container = button.closest(".code-window") || button.parentElement;
var code = container && container.querySelector("code");
if (!code || !navigator.clipboard) return;
navigator.clipboard.writeText(code.textContent).then(function () {
button.textContent = "copied";
setTimeout(function () { button.textContent = "copy"; }, 1400);
});
});
})();