From b45e9a3858c0a5c7e3494e6d3fa7940e6c19aec0 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 15 Sep 2025 14:57:58 +0800 Subject: fix: `this.openLightBox` is undefined due to scope issues --- src/lightbox.js | 13 ++++++------- 1 file 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); }); } -- cgit v1.2.3