Add photoswipe captions

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-08-14 19:30:36 +03:00
parent 2200d995ce
commit 140a6b938e
8 changed files with 80 additions and 11 deletions

View File

@@ -1,14 +1,41 @@
import PhotoSwipeLightbox from "photoswipe/lightbox";
import Masonry from "masonry-layout";
new PhotoSwipeLightbox({
const lightboxCaptionHeight = 5 * parseFloat(getComputedStyle(document.documentElement).fontSize);
const lightbox = new PhotoSwipeLightbox({
gallery: ".lightbox",
children: "a",
children: ".pswp-image",
showAnimationDuration: 300,
hideAnimationDuration: 300,
initialZoomLevel: "fit",
pswpModule: () => import("photoswipe"),
}).init();
padding: {
top: lightboxCaptionHeight,
bottom: lightboxCaptionHeight,
left: 0,
right: 0,
}
});
lightbox.on("uiRegister", function () {
lightbox.pswp.ui.registerElement({
name: "caption",
order: 9,
isButton: false,
appendTo: "root",
onInit: (el, _) => {
lightbox.pswp.on("change", () => {
const element = lightbox.pswp.currSlide.data.element;
el.innerHTML =
element?.parentElement.querySelector(".pswp-caption-content")
?.innerHTML || "";
});
},
});
});
lightbox.init();
const masonryContainers = document.querySelectorAll(".masonry");
masonryContainers.forEach((container) => {