-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 921 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function(window) {
var _ = require("../component-underscore");
var Backbone = require("../solutionio-backbone");
var Countdown = function(maxTime) {
this.maxTime = maxTime;
this.restTime = 0;
this.interval = 0;
_.extend(this, Backbone.Events);
};
Countdown.prototype.start = function() {
var me = this;
this.restTime = this.maxTime;
me.trigger('start', this.maxTime);
this.interval = window.setInterval(function() {
me.restTime = me.restTime - 1000;
me.trigger("tick", me.restTime);
if (me.restTime <= 0) {
me.stop();
}
}, 1000);
};
Countdown.prototype.stop = function() {
var me = this;
window.clearInterval(this.interval);
this.interval = 0;
me.trigger("stop", "Stopwatch stopped");
}
Countdown.prototype.isRunning = function() {
return (this.interval !== 0);
};
module.exports = Countdown;
})(window);