From 11e0bbedadcd950bb17bf4d97adfd0afb0bce713 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Tue, 16 Sep 2025 15:19:11 +0800 Subject: refactor: move image handling to shadow class - lightbox module no longer handles original image visibility - lightbox module no longer handles shadow placement - lightbox module now only fetch and use shadow object --- src/lightbox.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'src/lightbox.js') diff --git a/src/lightbox.js b/src/lightbox.js index 49884cc..f7dd8b3 100644 --- a/src/lightbox.js +++ b/src/lightbox.js @@ -53,33 +53,25 @@ export default class LightBox { * ============ */ + // open lightbox = open shadow + show overlay open(image) { - // hide and store original image - image.style.visibility = 'hidden'; this.currentImage = image; - // get shadow of this image const shadow = this.shadows[image.id] || new Shadow(image); if (!this.shadows[image.id]) { this.shadows[image.id] = shadow; } - // place and open shadow - if (!document.body.contains(shadow.element)) shadow.placeItself(); shadow.open(); - this.overlay.show(); } + // close lightbox = remove shadow + hide overlay close(image) { - // show and unstore original image - image.style.visibility = 'visible'; this.currentImage = null; - // close shadow - const shadow = this.shadows[image.id]; - if (!shadow) return; - shadow.close(); + if (!this.shadows[image.id]) return; + this.shadows[image.id].close(); this.overlay.hide(); } @@ -88,11 +80,4 @@ export default class LightBox { if (!this.currentImage) return; this.close(this.currentImage); } - - closeAll() { - this.images.forEach(image => { - this.close(image); - }); - this.overlay.hide(); - } } -- cgit v1.2.3