summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-15 14:57:58 +0800
committerEltrac <hi@guhub.cn>2025-09-15 14:57:58 +0800
commitb45e9a3858c0a5c7e3494e6d3fa7940e6c19aec0 (patch)
tree65feb829253e851983bdc6a1915b7cc85a661cd6
parent4868ab4549963d96b74f24d674a50eaed4303a47 (diff)
fix: `this.openLightBox` is undefined due to scope issues
-rw-r--r--src/lightbox.js13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/lightbox.js b/src/lightbox.js
index cd657da..8d7ea67 100644
--- a/src/lightbox.js
+++ b/src/lightbox.js
@@ -44,17 +44,16 @@ export default class LightBox {
return link;
}
- function addListener(link, image) {
+ this.images.forEach(image => {
+ // generate unique id for each image
+ image.id = crypto.randomUUID();
+ // make sure every image has a link
+ const link = wrapInLink(image);
+ // click link to open lightbox
link.addEventListener('click', e => {
e.preventDefault();
this.openLightBox(image);
});
- }
-
- this.images.forEach(image => {
- image.id = crypto.randomUUID(); // generate unique id for image
- const link = wrapInLink(image);
- addListener(link, image);
});
}