diff --git a/assets/application.js b/assets/application.js index 0681966..07e801e 100644 --- a/assets/application.js +++ b/assets/application.js @@ -240,26 +240,38 @@ Attentive.PresentationTimer = (function() { PresentationTimer.prototype.ensureEl = function() { if (!this.el) { - this.el = document.createElement('div'); + this.el = this._createDiv(); this.el.classList.add('timer'); } return this.el; }; + PresentationTimer.prototype._createDiv = function() { + return document.createElement('div'); + }; + + PresentationTimer.prototype.addClass = function(className) { + return this.ensureEl().classList.add(className); + }; + PresentationTimer.prototype.start = function() { this._runner = this.runner(); - return this.ensureEl().classList.add('running'); + return this.addClass('running'); }; PresentationTimer.prototype.runner = function() { var _this = this; return setTimeout(function() { - _this.render(); - _this.time += 1; - if (_this._runner != null) return _this.runner(); + return _this.handleRunner(); }, 1000); }; + PresentationTimer.prototype.handleRunner = function() { + this.render(); + this.time += 1; + if (this._runner != null) return this.runner(); + }; + PresentationTimer.prototype.stop = function() { clearTimeout(this._runner); this.ensureEl().classList.remove('running'); diff --git a/index.html b/index.html index c962821..b29c00a 100644 --- a/index.html +++ b/index.html @@ -133,12 +133,12 @@ -