From 1a4ad3e7dcb9f48047a5eca2826ffd392f23e5ac Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 15 Sep 2025 11:16:04 +0800 Subject: refactor: LightBox and Shadow classes for clarity and reuse Added section comments and reorganized methods in both LightBox and Shadow for better readability. Shadow now supports finding existing instances, tracks open state, and separates initialization logic. Improved animation handling and event binding for closing shadows. --- src/lightbox.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/lightbox.js') diff --git a/src/lightbox.js b/src/lightbox.js index d5db91d..3b25585 100644 --- a/src/lightbox.js +++ b/src/lightbox.js @@ -5,6 +5,12 @@ import Shadow from './shadow.js'; export default class LightBox { overlay = new Overlay(); + /** + * ============ + * Initializers + * ============ + */ + constructor({ container }) { this.container = container; this.init(); @@ -42,10 +48,17 @@ export default class LightBox { }); } + /** + * ============ + * Actions + * ============ + */ + openLightBox(image) { - const shadow = new Shadow(image); + const shadow = Shadow.find(image) || new Shadow(image); + shadow.open(); + this.overlay.add(shadow); this.overlay.show(); - shadow.open(); } } -- cgit v1.2.3