Skip to content

Commit 6dd5893

Browse files
committed
maint(pat gallery): Narrow the search path for the Photoswipe template element. It is just within the template.
1 parent 5abca91 commit 6dd5893

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/pat/gallery/gallery.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import "regenerator-runtime/runtime"; // needed for ``await`` support
33
import Base from "../../core/base";
44
import Parser from "../../core/parser";
55
import dom from "../../core/dom";
6+
import logging from "../../core/logging";
67
import utils from "../../core/utils";
78

9+
const log = logging.getLogger("pat.gallery");
10+
811
export const parser = new Parser("gallery");
912
parser.addArgument("item-selector", "a"); // selector for anchor element, which is added to the gallery.
1013
parser.addArgument("loop", true);
@@ -80,7 +83,14 @@ export default Base.extend({
8083
e.preventDefault();
8184

8285
this.template.removeAttribute("hidden");
83-
const pswpElement = document.querySelector(".pswp");
86+
87+
const pswp_el = dom.querySelectorAllAndMe(this.template, ".pswp")?.[0];
88+
if (!pswp_el) {
89+
log.warn("No photoswipe template found.");
90+
}
91+
92+
// Now - when all is set - prevent default action.
93+
e.preventDefault();
8494

8595
const index =
8696
this.images
@@ -103,7 +113,7 @@ export default Base.extend({
103113
history: false,
104114
};
105115

106-
const gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI, this.images, options);
116+
const gallery = new PhotoSwipe(pswp_el, PhotoSwipeUI, this.images, options);
107117
gallery.listen("gettingData", function (index, item) {
108118
// Workaround for the fact that we don't know the image sizes.
109119
// https://github.com/dimsemenov/PhotoSwipe/issues/796

0 commit comments

Comments
 (0)