fix: remove duplicate openLightbox/closeLightbox and dead code (#39)
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 26s

- Consolidate openLightbox() and closeLightbox() to single vanilla JS definition
- Remove orphaned keyboard handler block that caused ReferenceError
- Refs: #39
This commit is contained in:
2026-05-19 12:41:58 +00:00
parent 9a8776412e
commit 6b13b95102

View File

@@ -81,10 +81,6 @@ document.addEventListener("DOMContentLoaded", function () {
this.click(); this.click();
} }
}); });
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
$(this).trigger("click");
}
}); });
// Lightbox track last focused element for focus return // Lightbox track last focused element for focus return
@@ -92,27 +88,26 @@ document.addEventListener("DOMContentLoaded", function () {
function openLightbox(src) { function openLightbox(src) {
lightboxTrigger = document.activeElement; lightboxTrigger = document.activeElement;
$("#lightboxImg").attr("src", src).attr("alt", ""); document.getElementById("lightboxImg").setAttribute("src", src);
$("#lightbox").addClass("open"); document.getElementById("lightboxImg").setAttribute("alt", "");
$("body").css("overflow", "hidden"); document.getElementById("lightbox").classList.add("open");
document.body.style.overflow = "hidden";
// Set focus to close button // Set focus to close button
setTimeout(function () { setTimeout(function () {
$("#lightboxClose").focus(); document.getElementById("lightboxClose").focus();
}, 50); }, 50);
} }
function closeLightbox() { function closeLightbox() {
$("#lightbox").removeClass("open"); document.getElementById("lightbox").classList.remove("open");
$("body").css("overflow", ""); document.body.style.overflow = "";
// Return focus to trigger // Return focus to trigger
if (lightboxTrigger) { if (lightboxTrigger) {
$(lightboxTrigger).focus(); lightboxTrigger.focus();
lightboxTrigger = null; lightboxTrigger = null;
} }
} }
// Lightbox gallery grid items
// Lightbox gallery grid items // Lightbox gallery grid items
document.querySelectorAll(".grid-item").forEach(function (item) { document.querySelectorAll(".grid-item").forEach(function (item) {
item.addEventListener("click", function () { item.addEventListener("click", function () {
@@ -139,26 +134,7 @@ document.addEventListener("DOMContentLoaded", function () {
}); });
}); });
function openLightbox(src) {
lightboxTrigger = document.activeElement;
document.getElementById("lightboxImg").setAttribute("src", src);
document.getElementById("lightbox").classList.add("open");
document.body.style.overflow = "hidden";
// Focus close button
setTimeout(function () {
document.getElementById("lightboxClose").focus();
}, 100);
}
function closeLightbox() {
document.getElementById("lightbox").classList.remove("open");
document.body.style.overflow = "";
// Return focus to trigger
if (lightboxTrigger) {
lightboxTrigger.focus();
lightboxTrigger = null;
}
}
document.getElementById("lightboxClose").addEventListener("click", closeLightbox); document.getElementById("lightboxClose").addEventListener("click", closeLightbox);
document.getElementById("lightbox").addEventListener("click", function (e) { document.getElementById("lightbox").addEventListener("click", function (e) {