-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (78 loc) · 2.82 KB
/
Copy pathscript.js
File metadata and controls
89 lines (78 loc) · 2.82 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
(() => {
const yearEl = document.getElementById("year");
if (yearEl) yearEl.textContent = String(new Date().getFullYear());
const copyEmailButton = document.getElementById("copy-email-button");
if (copyEmailButton) {
const email = copyEmailButton.dataset.email || "";
const originalText = copyEmailButton.textContent;
let resetTimer = null;
const restoreLabel = () => {
copyEmailButton.textContent = originalText;
copyEmailButton.dataset.state = "";
};
const copyText = async (value) => {
if (navigator.clipboard?.writeText) {
await navigator.clipboard.writeText(value);
return;
}
const input = document.createElement("textarea");
input.value = value;
input.setAttribute("readonly", "");
input.style.position = "absolute";
input.style.left = "-9999px";
document.body.append(input);
input.select();
document.execCommand("copy");
input.remove();
};
copyEmailButton.addEventListener("click", async () => {
try {
await copyText(email);
copyEmailButton.textContent = "Copied email";
copyEmailButton.dataset.state = "done";
} catch {
copyEmailButton.textContent = "Copy failed";
copyEmailButton.dataset.state = "";
}
if (resetTimer) window.clearTimeout(resetTimer);
resetTimer = window.setTimeout(restoreLabel, 1600);
});
}
const prefersReducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
if (prefersReducedMotion) {
document
.querySelectorAll("[data-reveal]")
.forEach((el) => el.classList.add("is-revealed"));
} else {
// Apply stagger delays automatically for lists/grids.
const setStagger = (selector, stepMs, startMs = 0) => {
const nodes = document.querySelectorAll(selector);
nodes.forEach((el, i) => {
const existing = el.style.getPropertyValue("--d");
if (!existing) el.style.setProperty("--d", `${startMs + i * stepMs}ms`);
});
};
setStagger(".cards .card[data-reveal]", 70, 0);
setStagger(".timeline .timeline-item[data-reveal]", 60, 0);
// Make the header feel like a "page load" animation rather than a scroll reveal.
document
.querySelectorAll(".site-header[data-reveal]")
.forEach((el) => el.classList.add("is-revealed"));
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
entry.target.classList.add("is-revealed");
observer.unobserve(entry.target);
}
},
{ threshold: 0.12, rootMargin: "0px 0px -10% 0px" },
);
document.querySelectorAll("[data-reveal]").forEach((el) => {
if (el.classList.contains("is-revealed")) return;
observer.observe(el);
});
}
})();