1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-09-03 01:52:47 +02:00

Extracting autoslide to plugin

#51
This commit is contained in:
Antonio Laguna
2017-03-12 22:47:28 +01:00
parent a5cfa93eaa
commit d2e1ee0559
3 changed files with 52 additions and 31 deletions

View File

@@ -9,6 +9,7 @@ const CLASSES = {
// Default plugins
const PLUGINS = {
'autoslide': Plugins.AutoSlide,
'clickNav': Plugins.ClickNav,
'grid': Plugins.Grid,
'hash': Plugins.Hash,
@@ -89,12 +90,6 @@ export default class WebSlides {
* @type {Object}
*/
this.plugins = {};
/**
* Interval ID reference for the autoslide.
* @type {?number}
* @private
*/
this.interval_ = null;
/**
* Options dictionary.
* @type {Object}
@@ -122,7 +117,6 @@ export default class WebSlides {
this.grabSlides_();
this.createPlugins_();
this.initSlides_();
this.play();
// Finished
this.onInit_();
}
@@ -398,28 +392,4 @@ export default class WebSlides {
static registerPlugin(key, cto) {
PLUGINS[key] = cto;
}
/**
* Starts autosliding all the slides if it's not currently doing it and the
* autoslide option was a number greater than 0.
* @param {?number=} time Amount of milliseconds to wait to go to next slide
* automatically.
*/
play(time) {
time = time || this.options.autoslide;
if (!this.interval_ && typeof time === 'number' && time > 0) {
this.interval_ = setInterval(this.goNext.bind(this), time);
}
}
/**
* Stops autosliding all the slides.
*/
stop() {
if (this.interval_) {
clearInterval(this.interval_);
this.interval_ = null;
}
}
}

View File

@@ -0,0 +1,49 @@
import DOM from '../utils/dom';
/**
* Autoslide plugin.
*/
export default class AutoSlide {
/**
* @param {WebSlides} wsInstance The WebSlides instance
*/
constructor(wsInstance) {
/**
* @type {WebSlides}
* @private
*/
this.ws_ = wsInstance;
/**
* Interval ID reference for the autoslide.
* @type {?number}
* @private
*/
this.interval_ = null;
DOM.once(wsInstance.el, 'ws:init', this.play.bind(this));
}
/**
* Starts autosliding all the slides if it's not currently doing it and the
* autoslide option was a number greater than 0.
* @param {?number=} time Amount of milliseconds to wait to go to next slide
* automatically.
*/
play(time) {
time = time || this.ws_.options.autoslide;
if (!this.interval_ && typeof time === 'number' && time > 0) {
this.interval_ = setInterval(this.ws_.goNext.bind(this.ws_), time);
}
}
/**
* Stops autosliding all the slides.
*/
stop() {
if (this.interval_) {
clearInterval(this.interval_);
this.interval_ = null;
}
}
}

View File

@@ -1,3 +1,4 @@
import AutoSlide from './autoslide';
import ClickNav from './click-nav';
import Grid from './grid';
import Hash from './hash';
@@ -8,6 +9,7 @@ import Touch from './touch';
import Video from './video';
export default {
AutoSlide,
ClickNav,
Grid,
Hash,