diff options
| author | Eltrac <hi@guhub.cn> | 2025-09-15 14:57:58 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-09-15 14:57:58 +0800 |
| commit | b45e9a3858c0a5c7e3494e6d3fa7940e6c19aec0 (patch) | |
| tree | 65feb829253e851983bdc6a1915b7cc85a661cd6 /src/lightbox.js | |
| parent | 4868ab4549963d96b74f24d674a50eaed4303a47 (diff) | |
fix: `this.openLightBox` is undefined due to scope issues
Diffstat (limited to 'src/lightbox.js')
| -rw-r--r-- | src/lightbox.js | 13 |
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); }); } |
