From 03a16f8da4762b20065b647acd1915d5b27a8643 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 10 May 2026 14:28:24 +0200 Subject: feat: arrow key navigation in lightbox Left/right arrow keys move between photos; navigation stops at the first and last photo without wrapping around. Co-Authored-By: Claude Sonnet 4.6 --- templates/gallery.html | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'templates/gallery.html') diff --git a/templates/gallery.html b/templates/gallery.html index 4991a11..51a7196 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -24,9 +24,9 @@
-{{range .Photos}} -
-{{.}} +{{range $i, $p := .Photos}} +
+{{$p}}
{{end}}
@@ -83,7 +83,12 @@ function uploadFiles(files) { xhr.send(fd); } -function openLightbox(src) { +const photos = [{{range .Photos}}'/g/{{$.Name}}/photo/{{.}}',{{end}}]; +let currentIndex = -1; + +function openLightbox(index) { + currentIndex = index; + const src = photos[index]; document.getElementById('lightbox-img').src = src; document.getElementById('lightbox-download').href = src; document.getElementById('lightbox').classList.add('active'); @@ -91,8 +96,14 @@ function openLightbox(src) { function closeLightbox() { document.getElementById('lightbox').classList.remove('active'); document.getElementById('lightbox-img').src = ''; + currentIndex = -1; } -document.addEventListener('keydown', e => { if (e.key === 'Escape') closeLightbox(); }); +document.addEventListener('keydown', e => { + if (e.key === 'Escape') { closeLightbox(); return; } + if (currentIndex === -1) return; + if (e.key === 'ArrowRight' && currentIndex < photos.length - 1) openLightbox(currentIndex + 1); + if (e.key === 'ArrowLeft' && currentIndex > 0) openLightbox(currentIndex - 1); +}); -- cgit v1.3