| 1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
dojo.provide("dojo.lang.timing.Timer");
|
|
|
12 |
dojo.require("dojo.lang.func");
|
|
|
13 |
dojo.lang.timing.Timer = function (interval) {
|
|
|
14 |
this.timer = null;
|
|
|
15 |
this.isRunning = false;
|
|
|
16 |
this.interval = interval;
|
|
|
17 |
this.onStart = null;
|
|
|
18 |
this.onStop = null;
|
|
|
19 |
};
|
|
|
20 |
dojo.extend(dojo.lang.timing.Timer, {onTick:function () {
|
|
|
21 |
}, setInterval:function (interval) {
|
|
|
22 |
if (this.isRunning) {
|
|
|
23 |
dj_global.clearInterval(this.timer);
|
|
|
24 |
}
|
|
|
25 |
this.interval = interval;
|
|
|
26 |
if (this.isRunning) {
|
|
|
27 |
this.timer = dj_global.setInterval(dojo.lang.hitch(this, "onTick"), this.interval);
|
|
|
28 |
}
|
|
|
29 |
}, start:function () {
|
|
|
30 |
if (typeof this.onStart == "function") {
|
|
|
31 |
this.onStart();
|
|
|
32 |
}
|
|
|
33 |
this.isRunning = true;
|
|
|
34 |
this.timer = dj_global.setInterval(dojo.lang.hitch(this, "onTick"), this.interval);
|
|
|
35 |
}, stop:function () {
|
|
|
36 |
if (typeof this.onStop == "function") {
|
|
|
37 |
this.onStop();
|
|
|
38 |
}
|
|
|
39 |
this.isRunning = false;
|
|
|
40 |
dj_global.clearInterval(this.timer);
|
|
|
41 |
}});
|
|
|
42 |
|