Skip to content

Commit

Permalink
fix: lightgallery does not work when there are multiple DOM elements …
Browse files Browse the repository at this point in the history
…with the same class (#12)

修复匹配区域设置为 class 选择器时,无法打开图片的问题。

Fixes #10 

```release-note
修复匹配区域设置为 class 选择器时,无法打开图片的问题。
```
  • Loading branch information
ruibaby authored Nov 28, 2023
1 parent b64ffb7 commit 876cd46
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/run/halo/lightgallery/LightGalleryHeadProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ static String instantiateGallery(Set<String> domSelectors) {
if (node) {
node.dataset.src = node.src;
}
});
lightGallery(document.querySelector("%s"), {
selector: "img",
const galleries = document.querySelectorAll(`%s`);
if (galleries.length > 0) {
galleries.forEach(function (node) {
lightGallery(node, {
selector: "img",
});
});
}
});
""".formatted(domSelector, domSelector)
)
Expand Down

0 comments on commit 876cd46

Please sign in to comment.