forked from flamejs/flame.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repeater.js
41 lines (35 loc) · 1.04 KB
/
repeater.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
38
39
40
41
Flame.Repeater = Ember.Object.extend(Flame.ActionSupport, {
init: function() {
this._super();
this._scheduleNext();
},
stop: function() {
Ember.run.cancel(this._timer);
},
reschedule: function() {
this.stop();
this._scheduleNext();
},
_scheduleNext: function() {
//Use (new Date()).getTime() instead of Date.now() for IE-support.
var wait;
if (this.get('interval') === 0) {
wait = 0;
} else {
var lastInvocation = this.get('lastInvoke');
if (Ember.none(lastInvocation)) {
wait = this.get('interval');
} else {
wait = (new Date()).getTime() - lastInvocation + this.get('interval');
}
if (wait < 0) {
wait = 0;
}
}
this._timer = Ember.run.later(this, function() {
this.set('lastInvoke', (new Date()).getTime());
this.fireAction();
this._scheduleNext();
}, wait);
}
});