diff options
author | Victor Häggqvist <[email protected]> | 2016-01-14 22:54:43 +0100 |
---|---|---|
committer | Victor Häggqvist <[email protected]> | 2016-01-14 22:54:43 +0100 |
commit | 382401d527314b270e1c67b4f88cd3bfbca81d46 (patch) | |
tree | 77c4831118fc9fd2d19e044ce5ffb60b8533163f /src/LightBox.js | |
parent | dd52fd3f463c254cf54309db848aa88899caeaa0 (diff) |
create plugin architecture
Diffstat (limited to '')
-rw-r--r-- | src/LightBox.js | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/LightBox.js b/src/LightBox.js index b9f6b03..5479819 100644 --- a/src/LightBox.js +++ b/src/LightBox.js @@ -26,10 +26,6 @@ export class LightBox { quitOnEnd: false, quitOnImgClick: false, quitOnDocClick: true, - onStart: false, - onEnd: false, - onLoadStart: false, - onLoadEnd: false, }; this.options = Object.assign(options, defaultOptions); @@ -46,6 +42,12 @@ export class LightBox { this.swipeEnd = 0; this.imagePosLeft = 0; + + this.onStartListeners = []; + this.onEndListeners = []; + this.onLoadStartListeners = []; + this.onLoadEndListeners = []; + this.bindEvents(); } @@ -112,8 +114,9 @@ export class LightBox { setTimeout(() => { this.removeImage(); this.inProgress = false; - if (this.options.onEnd !== false) - this.options.onEnd(); + + this.onEndListeners.forEach(l => l()); + }, this.options.animationSpeed); } @@ -129,7 +132,7 @@ export class LightBox { this.inProgress = false; - if (this.options.onStart !== false ) this.options.onStart(); + this.onStartListeners.forEach(l => l()); this.target = element; @@ -183,7 +186,7 @@ export class LightBox { } this.inProgress = true; - if (this.options.onLoadStart !== false) this.options.onLoadStart(); + this.onLoadStartListeners.forEach(l => l()); setTimeout(() => { log.debug('loadImage in'); @@ -209,6 +212,7 @@ export class LightBox { setTimeout(() => { this.inProgress = false; + this.onLoadEndListeners.forEach(l => l()); }, this.options.animationSpeed); if (this.options.preloadNext) { @@ -375,6 +379,26 @@ export class LightBox { log.debug('resized'); this.setImage(); } + + addOnStartListener(listener) { + this.onStartListeners.push(listener); + } + + addOnEndListener(listener) { + this.onEndListeners.push(listener); + } + + addOnLoadStartListener(listener) { + this.onLoadStartListeners.push(listener); + } + + addOnLoadEndListener(listener) { + this.onLoadEndListeners.push(listener); + } + + registerPlugin(plugin) { + plugin.register(this); + } } LightBox.HAS_TOUCH = ('ontouchstart' in window); |