Sha256: 6ab684354b335318a1b2adb8d2e41a92db57e1e92b70fe911037388cb425eb8c
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
'use strict'; import $ from 'jquery'; function Timer(elem, options, cb) { var _this = this, duration = options.duration,//options is an object for easily adding features later. nameSpace = Object.keys(elem.data())[0] || 'timer', remain = -1, start, timer; this.isPaused = false; this.restart = function() { remain = -1; clearTimeout(timer); this.start(); } this.start = function() { this.isPaused = false; // if(!elem.data('paused')){ return false; }//maybe implement this sanity check if used for other things. clearTimeout(timer); remain = remain <= 0 ? duration : remain; elem.data('paused', false); start = Date.now(); timer = setTimeout(function(){ if(options.infinite){ _this.restart();//rerun the timer. } if (cb && typeof cb === 'function') { cb(); } }, remain); elem.trigger(`timerstart.zf.${nameSpace}`); } this.pause = function() { this.isPaused = true; //if(elem.data('paused')){ return false; }//maybe implement this sanity check if used for other things. clearTimeout(timer); elem.data('paused', true); var end = Date.now(); remain = remain - (end - start); elem.trigger(`timerpaused.zf.${nameSpace}`); } } export {Timer};
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foundation-rails-6.4.1.0 | vendor/assets/js/foundation.util.timer.js.es6 |