const lightbox = document.getElementById("screenshot-lightbox"); const lightboxImage = document.getElementById("lightbox-image"); const lightboxCaption = document.getElementById("lightbox-caption"); const zoomableScreenshots = document.querySelectorAll(".zoomable-screenshot"); if (lightbox && lightboxImage && lightboxCaption && zoomableScreenshots.length) { const closeLightbox = () => { lightbox.classList.remove("is-open"); lightbox.setAttribute("aria-hidden", "true"); lightboxImage.removeAttribute("src"); lightboxImage.alt = ""; lightboxCaption.textContent = ""; document.body.classList.remove("lightbox-open"); }; const openLightbox = (image) => { lightboxImage.src = image.currentSrc || image.src; lightboxImage.alt = image.alt; lightboxCaption.textContent = image.dataset.caption || image.alt || ""; lightbox.classList.add("is-open"); lightbox.setAttribute("aria-hidden", "false"); document.body.classList.add("lightbox-open"); }; zoomableScreenshots.forEach((image) => { image.setAttribute("role", "button"); image.addEventListener("click", () => { openLightbox(image); }); image.addEventListener("keydown", (event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); openLightbox(image); } }); }); lightbox.addEventListener("click", (event) => { if (event.target.hasAttribute("data-lightbox-close")) { closeLightbox(); } }); document.addEventListener("keydown", (event) => { if (event.key === "Escape" && lightbox.classList.contains("is-open")) { closeLightbox(); } }); }