-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
178 lines (167 loc) · 6.09 KB
/
Copy pathscript.js
File metadata and controls
178 lines (167 loc) · 6.09 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"use strict";
// The content and source links work without JavaScript. Only the galleries
// and enlarged screenshot view are progressively enhanced.
document.querySelectorAll("[data-gallery]").forEach((gallery) => {
const controls = gallery.querySelector(".gallery-controls");
if (!controls) return;
controls.hidden = false;
const image = gallery.querySelector("img");
const link = gallery.querySelector("[data-enlarge]");
const caption = gallery.querySelector("[data-image-caption]");
controls.addEventListener("click", (event) => {
const button = event.target.closest("button[data-src]");
if (!button) return;
controls.querySelectorAll("button").forEach((item) => {
item.setAttribute("aria-pressed", String(item === button));
});
image.src = button.dataset.src;
image.alt = button.dataset.alt;
link.href = button.dataset.src;
link.dataset.caption = button.dataset.alt + " — " + button.dataset.caption;
link.setAttribute("aria-label", "Enlarge " + button.dataset.alt);
caption.textContent = button.dataset.caption;
});
});
const dialog = document.getElementById("image-dialog");
const dialogImage = document.getElementById("dialog-image");
const dialogCaption = document.getElementById("dialog-caption");
let opener = null;
if (dialog && typeof dialog.showModal === "function") {
document.querySelectorAll("[data-enlarge]").forEach((link) => {
link.addEventListener("click", (event) => {
// Preserve browser-native open-in-new-tab behavior.
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)
return;
event.preventDefault();
opener = link;
dialogImage.src = link.href;
dialogImage.alt = link.querySelector("img").alt;
dialogCaption.textContent = link.dataset.caption;
dialog.showModal();
});
});
dialog
.querySelector(".dialog-close")
.addEventListener("click", () => dialog.close());
dialog.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
event.preventDefault();
dialog.close();
}
});
dialog.addEventListener("click", (event) => {
if (event.target !== dialog) return;
const rect = dialog.getBoundingClientRect();
if (
event.clientX < rect.left ||
event.clientX > rect.right ||
event.clientY < rect.top ||
event.clientY > rect.bottom
)
dialog.close();
});
dialog.addEventListener("close", () => {
opener?.focus();
});
}
document.getElementById("year").textContent = String(new Date().getFullYear());
// Native scrolling stays in charge. Render at most once per scroll frame,
// with smaller hero travel on phones and no perpetual hero animation loop.
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
const narrowViewport = window.matchMedia("(max-width: 900px)");
const hero = document.querySelector(".hero");
const layers = [...document.querySelectorAll("[data-parallax]")];
const progress = document.querySelector(".scroll-progress");
let framePending = false;
let heroVisible = true;
// Keep the platform strip independent of page parallax so touch, trackpad,
// and keyboard scrolling never fight an automatic transform.
const platformScroller = document.querySelector(".era-scroll");
if (platformScroller) {
platformScroller.addEventListener("keydown", (event) => {
if (event.altKey || event.ctrlKey || event.metaKey) return;
const steps = {
ArrowLeft: -80,
ArrowRight: 80,
Home: -platformScroller.scrollWidth,
End: platformScroller.scrollWidth,
};
if (!(event.key in steps)) return;
event.preventDefault();
platformScroller.scrollBy({ left: steps[event.key], behavior: "instant" });
});
}
function renderScroll() {
framePending = false;
const y = window.scrollY;
const range = document.documentElement.scrollHeight - window.innerHeight;
if (progress)
progress.style.transform = `scaleX(${range > 0 ? Math.min(1, Math.max(0, y / range)) : 0})`;
if (reducedMotion.matches || document.hidden) return;
const intensity = narrowViewport.matches ? 0.35 : 1;
if (heroVisible) {
layers.forEach((layer) => {
const offset = Math.max(
-90,
Math.min(90, y * Number(layer.dataset.parallax) * intensity),
);
layer.style.setProperty("--parallax-y", `${offset.toFixed(1)}px`);
});
}
}
function scheduleScroll() {
if (!framePending) {
framePending = true;
window.requestAnimationFrame(renderScroll);
}
}
if ("IntersectionObserver" in window) {
const activityObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.target === hero) heroVisible = entry.isIntersecting;
});
scheduleScroll();
},
{ rootMargin: "100px" },
);
if (hero) activityObserver.observe(hero);
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0, rootMargin: "0px 0px -24px 0px" },
);
document.querySelectorAll("[data-reveal]").forEach((element) => {
if (
!reducedMotion.matches &&
element.getBoundingClientRect().top >= window.innerHeight
) {
element.classList.add("reveal-ready");
revealObserver.observe(element);
}
});
}
reducedMotion.addEventListener("change", () => {
if (reducedMotion.matches) {
layers.forEach((layer) => layer.style.removeProperty("--parallax-y"));
document
.querySelectorAll(".reveal-ready")
.forEach((element) => element.classList.add("is-visible"));
}
scheduleScroll();
});
window.addEventListener("scroll", scheduleScroll, { passive: true });
window.addEventListener("resize", scheduleScroll, { passive: true });
window.addEventListener("load", scheduleScroll, { once: true });
document.addEventListener("visibilitychange", scheduleScroll);
document.fonts?.ready.then(scheduleScroll);
scheduleScroll();
if (platformScroller && typeof enhancePlatformStrip === "function") {
enhancePlatformStrip(platformScroller, reducedMotion);
}