From 75de8a46ace7e879630e3a70584c52ef9242cc19 Mon Sep 17 00:00:00 2001 From: Antonio Laguna Date: Sat, 28 Jan 2017 16:27:15 +0100 Subject: [PATCH] Reworking the plugins --- src/modules/webslides.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/modules/webslides.js b/src/modules/webslides.js index 7d7bcf6..78a7063 100644 --- a/src/modules/webslides.js +++ b/src/modules/webslides.js @@ -8,7 +8,9 @@ const CLASSES = { VERTICAL: 'vertical' }; -const PLUGINS = ['Navigation']; +const PLUGINS = { + 'nav': Plugins.Navigation +}; export default class WebSlides { constructor() { @@ -31,6 +33,7 @@ export default class WebSlides { this.initSlides_(); Hash.init(this); + this.onInit_(); } removeChildren_() { @@ -47,16 +50,16 @@ export default class WebSlides { } createPlugins_() { - PLUGINS.forEach(pluginName => { - if (Plugins[pluginName]) { - const pluginCto = Plugins[pluginName]; - this.plugins[pluginCto] = new pluginCto(this); - } else { - throw new Error(`Tried to initialize plugin ${pluginName} but doesn't exist.`); - } + Object.keys(PLUGINS).forEach(pluginName => { + const pluginCto = PLUGINS[pluginName]; + this.plugins[pluginCto] = new pluginCto(this); }); } + onInit_() { + DOM.fireEvent(this.el, 'ws:init'); + } + grabSlides_() { this.slides = Array.from(this.el.childNodes) .map((slide, i) => new Slide(slide, i)); @@ -133,6 +136,11 @@ export default class WebSlides { this.isMoving = false; Hash.setSlideNumber(this.currentSlideI_ + 1); + DOM.fireEvent(this.el, 'ws:slide-change', { + slides: this.maxSlide_, + currentSlide0: this.currentSlideI_, + currentSlide: this.currentSlideI_ + 1 + }); } goNext() {