diff options
| author | Eltrac <hi@guhub.cn> | 2025-09-16 15:19:11 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-09-16 15:19:11 +0800 |
| commit | 11e0bbedadcd950bb17bf4d97adfd0afb0bce713 (patch) | |
| tree | 9aca0b99595eeb8dc9b283ba0ef571eaf369de27 /src/lightbox.js | |
| parent | f4f5d842dfb398e9da599fe2534167e95cc1d6b9 (diff) | |
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
Diffstat (limited to 'src/lightbox.js')
| -rw-r--r-- | src/lightbox.js | 23 |
1 files changed, 4 insertions, 19 deletions
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(); - } } |
