diff options
| author | Eltrac <hi@guhub.cn> | 2025-09-15 11:16:04 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-09-15 11:16:04 +0800 |
| commit | 1a4ad3e7dcb9f48047a5eca2826ffd392f23e5ac (patch) | |
| tree | c9be2180435651d88f531a52880e4b67b667c64b /src/lightbox.js | |
| parent | 5aeb745f381787758144d50667b0cf73d911a674 (diff) | |
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.
Diffstat (limited to 'src/lightbox.js')
| -rw-r--r-- | src/lightbox.js | 17 |
1 files changed, 15 insertions, 2 deletions
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(); } } |
