-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
315 lines (273 loc) · 9.34 KB
/
Copy pathscript.js
File metadata and controls
315 lines (273 loc) · 9.34 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/**
* Renders the whole page from PORTFOLIO (data.js), then wires up the lightbox.
*/
const ROMAN_NUMERALS = [
[1000, "M"], [900, "CM"], [500, "D"], [400, "CD"],
[100, "C"], [90, "XC"], [50, "L"], [40, "XL"],
[10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"],
];
function toRoman(num) {
let result = "";
let remaining = num;
for (const [value, symbol] of ROMAN_NUMERALS) {
while (remaining >= value) {
result += symbol;
remaining -= value;
}
}
return result;
}
function imgPath(folder, n) {
return `images/${folder}/${folder}-${n}.webp`;
}
function thumbPath(folder, n) {
return `images/${folder}/thumbs/${folder}-${n}.webp`;
}
function galleryImageMeta(gallery, item) {
const n = typeof item === "object" ? item.n : item;
const alt = typeof item === "object" && item.alt ? item.alt : gallery.defaultAlt;
return { n, alt, thumb: thumbPath(gallery.folder, n), full: imgPath(gallery.folder, n) };
}
function renderNav(pieces, hero) {
const links = pieces
.map((piece) => `<a href="#${piece.id}">${piece.title}</a>`)
.join("");
const logo = hero.image ? `<img class="brand__logo" src="${hero.image}" alt="" />` : "";
return `
<header class="site-header">
<div class="site-header__row">
<a class="brand" href="#top">${logo}Evangelia Batoglou</a>
<a class="nav-cta" href="#works"><span class="nav-cta__label">Works</span><span class="nav-cta__icon" aria-hidden="true">→</span></a>
</div>
<div class="quick-nav-wrap">
<nav class="quick-nav" aria-label="Jump to a piece">${links}</nav>
</div>
</header>
`;
}
function renderHero(hero) {
const description = hero.description.map((line) => `<span>${line}</span>`).join("");
const cta = hero.cta
.map((btn) => {
const cls = btn.primary ? "link-arrow link-arrow--primary" : "link-arrow";
const target = btn.external ? ' target="_blank" rel="noopener noreferrer"' : "";
const arrow = btn.external ? "↗" : "→";
return `<a class="${cls}" href="${btn.href}"${target}>${btn.label} <span aria-hidden="true">${arrow}</span></a>`;
})
.join("");
const art = hero.image
? `<div class="hero__art"><img src="${hero.image}" alt="Illustrated portrait of Evangelia Batoglou dancing" /></div>`
: "";
return `
<section id="top" class="hero">
<div class="hero__grid">
<div class="hero__content">
<p class="eyebrow">${hero.eyebrow}</p>
<h1>${hero.title}<span class="hero__tagline">${hero.tagline}</span></h1>
<div class="hero__description">${description}</div>
<div class="hero__cta">${cta}</div>
</div>
${art}
</div>
</section>
`;
}
function renderVideos(videos) {
if (!videos || !videos.length) return "";
const links = videos
.map(
(v) =>
`<a class="video-link" href="${v.url}" target="_blank" rel="noopener noreferrer"><span class="video-link__icon">▶</span>${v.label}</a>`
)
.join("");
return `
<p class="entry__watch">
<b>Watch</b>
<span class="sources sources--videos">${links}</span>
</p>
`;
}
function renderGallery(gallery) {
if (!gallery) return "";
const imgs = gallery.images
.map((item) => {
const meta = galleryImageMeta(gallery, item);
return `<img src="${meta.thumb}" data-full="${meta.full}" alt="${meta.alt}" loading="lazy" />`;
})
.join("");
return `
<div class="entry__gallery">
<p class="photos">
<b>Gallery</b>
<span class="gallery">${imgs}</span>
</p>
</div>
`;
}
function renderEvent(event) {
if (!event) return "";
return `<a class="entry__event" href="${event.url}" target="_blank" rel="noopener noreferrer">Event: ${event.label}</a>`;
}
function renderFeatureImage(piece) {
if (!piece.gallery) return "";
const meta = galleryImageMeta(piece.gallery, piece.gallery.images[0]);
return `
<div class="entry__media">
<img src="${meta.full}" alt="${meta.alt}" loading="lazy" />
</div>
`;
}
function renderPiece(piece, index) {
const number = toRoman(index + 1);
const subtitle = piece.subtitle ? `<span class="piece__subtitle">${piece.subtitle}</span>` : "";
const yearLine = piece.year ? `<p class="entry__meta">${piece.year}</p>` : "";
const eventLine = piece.event ? `<p class="entry__meta">${renderEvent(piece.event)}</p>` : "";
const description = piece.description.map((line) => `<span>${line}</span>`).join("");
const media = renderFeatureImage(piece);
return `
<article id="${piece.id}" class="entry${media ? "" : " entry--no-media"}">
<div class="entry__split">
${media}
<div class="entry__content">
<span class="entry__index">${number}</span>
<h2>${piece.title}${subtitle}</h2>
${yearLine}
${eventLine}
<div class="description">${description}</div>
${renderVideos(piece.videos)}
</div>
</div>
${renderGallery(piece.gallery)}
</article>
`;
}
function renderResources(resources) {
if (!resources) return "";
const links = resources.links
.map(
(link) =>
`<a class="resource-link" href="${link.url}" target="_blank" rel="noopener noreferrer">
<span class="resource-link__icon">☰</span>
<span class="resource-link__label">${link.label}</span>
<span class="resource-link__arrow" aria-hidden="true">→</span>
</a>`
)
.join("");
return `
<section class="resources">
<p class="entry__watch">
<b>${resources.label}</b>
<span class="sources sources--resources">${links}</span>
</p>
</section>
`;
}
function renderFooter(footer) {
const target = document.querySelector("footer");
target.innerHTML = `
<span>${footer.text}</span>
<a href="${footer.url}" target="_blank" rel="noopener noreferrer">${footer.name}</a>
<i>${footer.emoji}</i>
`;
}
function renderPage() {
document.querySelector("#nav-root").innerHTML = renderNav(PORTFOLIO.pieces, PORTFOLIO.hero);
document.querySelector("#hero-root").innerHTML = renderHero(PORTFOLIO.hero);
const works = document.querySelector("#works");
works.innerHTML =
PORTFOLIO.pieces.map(renderPiece).join("") + renderResources(PORTFOLIO.resources);
renderFooter(PORTFOLIO.footer);
}
function initLightbox() {
const lightbox = document.getElementById("lightbox");
const lbImage = lightbox.querySelector("img");
const counter = lightbox.querySelector(".lb-counter");
const closeBtn = document.getElementById("close");
const prevBtn = lightbox.querySelector(".lb-prev");
const nextBtn = lightbox.querySelector(".lb-next");
let currentImages = [];
let currentIndex = 0;
function updateNavButtons() {
prevBtn.disabled = currentIndex === 0;
nextBtn.disabled = currentIndex === currentImages.length - 1;
counter.textContent = `${currentIndex + 1} / ${currentImages.length}`;
}
function openLightbox(allImages, index) {
currentImages = allImages;
currentIndex = index;
lbImage.src = currentImages[index].dataset.full || currentImages[index].src;
lbImage.alt = currentImages[index].alt || "";
lightbox.classList.add("is-open");
updateNavButtons();
}
function showImage(index) {
currentIndex = index;
const img = currentImages[currentIndex];
lbImage.style.transform = "scale(0.95)";
setTimeout(() => {
lbImage.src = img.dataset.full || img.src;
lbImage.alt = img.alt || "";
lbImage.style.transform = "scale(1)";
updateNavButtons();
}, 120);
}
function showPrevImage() {
if (currentIndex > 0) showImage(currentIndex - 1);
}
function showNextImage() {
if (currentIndex < currentImages.length - 1) showImage(currentIndex + 1);
}
function closeLightbox() {
lightbox.classList.remove("is-open");
}
document.querySelectorAll(".gallery").forEach((gallery) => {
const images = Array.from(gallery.querySelectorAll("img"));
images.forEach((img, index) => {
img.addEventListener("click", () => openLightbox(images, index));
});
});
prevBtn.addEventListener("click", (e) => {
e.stopPropagation();
showPrevImage();
});
nextBtn.addEventListener("click", (e) => {
e.stopPropagation();
showNextImage();
});
closeBtn.addEventListener("click", closeLightbox);
lightbox.addEventListener("click", (e) => {
if (e.target === lightbox) closeLightbox();
});
document.addEventListener("keydown", (e) => {
if (!lightbox.classList.contains("is-open")) return;
if (e.key === "Escape") closeLightbox();
else if (e.key === "ArrowLeft") showPrevImage();
else if (e.key === "ArrowRight") showNextImage();
});
}
function initQuickNavScroll() {
const quickNav = document.querySelector(".quick-nav");
if (!quickNav) return;
quickNav.addEventListener(
"wheel",
(e) => {
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
quickNav.scrollLeft += e.deltaY;
e.preventDefault();
},
{ passive: false }
);
}
function initHeaderScrollState() {
const header = document.querySelector(".site-header");
if (!header) return;
const onScroll = () => header.classList.toggle("is-scrolled", window.scrollY > 12);
document.addEventListener("scroll", onScroll, { passive: true });
onScroll();
}
document.addEventListener("DOMContentLoaded", () => {
renderPage();
initLightbox();
initHeaderScrollState();
initQuickNavScroll();
});