Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
248 lines (206 loc) · 8.94 KB
/
Copy pathscript.js
File metadata and controls
248 lines (206 loc) · 8.94 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
const HERO_QUOTES = [
"I’m usually brought in after the easy answers fail.",
"If I’ve been brought in, your project has probably already gone terribly wrong.",
"SysOps is only useful after the system is proven to run.",
"I ask hard questions before they become expensive ones.",
"Complicated is manageable. Unexplained is where our trouble starts.",
"The fix should be maintainable after the developer leaves.",
"Good boundaries keep small problems from developing careers.",
"Over engineer? I build for the Tuesday after launch.",
"AI is the next generation’s IDE. The engineer still owns the result.",
"AI agents are useful. Boundaries make them dependable.",
"AWS works best when the bill and boundaries are understood.",
"Python is the X-Type car. PHP is the Z-Type car. Both get you there. They’re just built for different roads.",
"What’s Node to love? One language from browser to backend.",
"Rust ironically prevents corrosion.",
"Docker solves packaging. It does not solve ownership.",
"Git and PostgreSQL remember everything, including decisions nobody documented.",
"MCP is useful when tools have clear permissions and more importantly, honest receipts.",
"Local inference; own your AI, own your workflow.",
"Durable web architecture makes the next change routine, not an adventure.",
"Leaders who replace people with AI agents own the ask, happy ending or not. (Without governance, I’m betting on the latter.)"
];
document.addEventListener("DOMContentLoaded", () => {
const menuButton = document.querySelector(".menu-toggle");
const mobileNavigation = document.querySelector("#mobile-navigation");
if (menuButton && mobileNavigation) {
const closeMenu = () => {
menuButton.setAttribute("aria-expanded", "false");
mobileNavigation.hidden = true;
};
menuButton.addEventListener("click", () => {
const willOpen = menuButton.getAttribute("aria-expanded") !== "true";
menuButton.setAttribute("aria-expanded", String(willOpen));
mobileNavigation.hidden = !willOpen;
});
mobileNavigation.addEventListener("click", (event) => {
if (event.target.closest("a")) closeMenu();
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape" && !mobileNavigation.hidden) {
closeMenu();
menuButton.focus();
}
});
window.addEventListener("resize", () => {
if (window.innerWidth > 1120) closeMenu();
});
}
const locationLinks = [...document.querySelectorAll(".header-segment[href^='#']")];
const locationMap = new Map([
["#work", "#work"],
["#writing", "#writing"],
["#about", "#about"],
["#principles", "#about"]
]);
const locationSections = ["#work", "#writing", "#about"]
.map((selector) => ({
element: document.querySelector(selector),
href: locationMap.get(selector)
}))
.filter(({ element }) => element);
if (locationLinks.length && locationSections.length) {
let hashNavigationTarget = null;
let hashNavigationTimer = null;
const setActiveLocation = (href = null) => {
locationLinks.forEach((link) => {
if (link.getAttribute("href") === href) {
link.setAttribute("aria-current", "location");
} else {
link.removeAttribute("aria-current");
}
});
};
const updateLocationFromViewport = () => {
if (hashNavigationTarget) return;
const activationLine = window.innerHeight * 0.31;
const activeSection = locationSections.find(({ element }) => {
const bounds = element.getBoundingClientRect();
return bounds.top <= activationLine && bounds.bottom > activationLine;
});
setActiveLocation(activeSection?.href);
};
const releaseHashNavigation = () => {
if (!hashNavigationTarget) return;
hashNavigationTarget = null;
window.clearTimeout(hashNavigationTimer);
hashNavigationTimer = null;
updateLocationFromViewport();
};
const updateLocationFromHash = () => {
const mappedLocation = locationMap.get(window.location.hash);
if (!mappedLocation) {
hashNavigationTarget = null;
updateLocationFromViewport();
return;
}
hashNavigationTarget = mappedLocation;
setActiveLocation(mappedLocation);
window.clearTimeout(hashNavigationTimer);
hashNavigationTimer = window.setTimeout(releaseHashNavigation, 1200);
};
const locationObserver = new IntersectionObserver(updateLocationFromViewport, {
rootMargin: "-30% 0px -69% 0px"
});
locationSections.forEach(({ element }) => locationObserver.observe(element));
window.addEventListener("hashchange", updateLocationFromHash);
window.addEventListener("scrollend", releaseHashNavigation);
window.addEventListener("resize", updateLocationFromViewport);
if (locationMap.has(window.location.hash)) {
updateLocationFromHash();
} else {
window.requestAnimationFrame(updateLocationFromViewport);
}
}
const year = document.querySelector("[data-year]");
if (year) year.textContent = String(new Date().getFullYear());
const emailLink = document.querySelector("[data-email-link]");
if (emailLink) {
const decode = (parts) => parts.map((part) => window.atob(part)).join("");
const account = decode(["Y29u", "dGFj", "dA=="]);
const host = decode(["am9z", "ZWZm", "Yi5j", "b20="]);
const address = `${account}${String.fromCharCode(64)}${host}`;
const scheme = [109, 97, 105, 108, 116, 111, 58]
.map((code) => String.fromCharCode(code))
.join("");
emailLink.firstChild.nodeValue = `${address} `;
emailLink.href = `${scheme}${address}`;
emailLink.setAttribute("aria-label", `Email Joseff at ${address}`);
}
const quoteText = document.querySelector("[data-hero-quote]");
if (quoteText) {
const shuffleQuotes = (previousQuote = null) => {
const shuffled = [...HERO_QUOTES];
for (let index = shuffled.length - 1; index > 0; index -= 1) {
const randomIndex = Math.floor(Math.random() * (index + 1));
[shuffled[index], shuffled[randomIndex]] = [shuffled[randomIndex], shuffled[index]];
}
if (previousQuote && shuffled[0] === previousQuote) {
const swapIndex = 1 + Math.floor(Math.random() * (shuffled.length - 1));
[shuffled[0], shuffled[swapIndex]] = [shuffled[swapIndex], shuffled[0]];
}
return shuffled;
};
let quoteOrder = shuffleQuotes();
let quoteIndex = 0;
quoteText.textContent = quoteOrder[quoteIndex];
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reducedMotion) {
window.setInterval(() => {
const previousQuote = quoteOrder[quoteIndex];
if (quoteIndex === quoteOrder.length - 1) {
quoteOrder = shuffleQuotes(previousQuote);
quoteIndex = 0;
} else {
quoteIndex += 1;
}
quoteText.classList.add("is-changing");
window.setTimeout(() => {
quoteText.textContent = quoteOrder[quoteIndex];
quoteText.classList.remove("is-changing");
}, 200);
}, 8000);
}
}
const caseStudyTabList = document.querySelector("#ai-backoffice .volume-tabs[role='tablist']");
if (caseStudyTabList) {
const tabs = [...caseStudyTabList.querySelectorAll("[role='tab']")];
const activateCaseStudyTab = (activeIndex, moveFocus = false) => {
tabs.forEach((tab, index) => {
const isActive = index === activeIndex;
const panel = document.getElementById(tab.getAttribute("aria-controls"));
tab.classList.toggle("is-active", isActive);
tab.setAttribute("aria-selected", String(isActive));
tab.tabIndex = isActive ? 0 : -1;
if (panel) panel.hidden = !isActive;
});
document.querySelectorAll("#ai-backoffice [data-publication-cover]").forEach((cover) => {
cover.hidden = Number(cover.dataset.publicationCover) !== activeIndex;
});
if (moveFocus) tabs[activeIndex]?.focus();
};
tabs.forEach((tab, index) => {
tab.addEventListener("click", () => activateCaseStudyTab(index));
tab.addEventListener("keydown", (event) => {
let nextIndex = null;
if (event.key === "ArrowLeft") {
nextIndex = (index - 1 + tabs.length) % tabs.length;
} else if (event.key === "ArrowRight") {
nextIndex = (index + 1) % tabs.length;
} else if (event.key === "Home") {
nextIndex = 0;
} else if (event.key === "End") {
nextIndex = tabs.length - 1;
}
if (nextIndex === null) return;
event.preventDefault();
activateCaseStudyTab(nextIndex, true);
});
});
const initialIndex = tabs.findIndex((tab) => tab.getAttribute("aria-selected") === "true");
activateCaseStudyTab(initialIndex >= 0 ? initialIndex : 0);
document.querySelectorAll("a[href='#ai-backoffice']").forEach((link) => {
link.addEventListener("click", () => activateCaseStudyTab(0));
});
}
});