Skip to content

Commit

Permalink
New: Add captions to PhotoSwipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Jul 25, 2024
1 parent 2bfffc1 commit e060ac6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Resources/Private/Assets/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PhotoSwipeLightbox from "photoswipe/lightbox";
import PhotoSwipeDynamicCaption from "photoswipe-dynamic-caption-plugin";
import { dispatchEvent, getDataOptions, setPswpContainerAttributes, addEventListener } from "./Helper";

const optionsFromNeos = { ...getDataOptions("photoswipeI18n"), ...getDataOptions("photoswipeOptions") };
Expand All @@ -10,6 +11,12 @@ function init(options = {}) {
pswpModule: () => import("photoswipe"),
...options,
});
new PhotoSwipeDynamicCaption(lightbox, {
type: "auto",
captionContent: (slide) =>
slide.data.element.closest("figure").querySelector(".pswp-caption-content")?.innerHTML || "",
});

lightbox.on("firstUpdate", setPswpContainerAttributes);
lightbox.on("contentLoadImage", ({ content, isLazy }) => {
dispatchEvent({ type: "image", action: "open", content, isLazy });
Expand Down
7 changes: 6 additions & 1 deletion Resources/Private/Assets/Main.pcss
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@import url("photoswipe/src/photoswipe.css");
@import url("photoswipe-dynamic-caption-plugin/photoswipe-dynamic-caption-plugin.css");

:is(.pswp--fetch, .pswp--template) .pswp__zoom-wrap {
position: relative;
/* stylelint-disable-next-line declaration-block-no-duplicate-properties */
width: 100vw;
height: 100vh;
/* stylelint-disable-next-line declaration-block-no-duplicate-properties */
width: 100dvw;
height: 100dvh;
}
Expand Down Expand Up @@ -40,3 +41,7 @@
.pswp--fetch-loading .jonnitto-photoswipe-content {
pointer-events: none;
}

.pswp-caption-content {
display: none;
}
2 changes: 1 addition & 1 deletion Resources/Public/Modules/Main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Resources/Public/Modules/Main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/Public/Scripts/Main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Resources/Public/Scripts/Main.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit e060ac6

Please sign in to comment.