| 1 |
define(["dojo/_base/kernel", "dojo/_base/lang"], function(dojo){ |
| 2 |
dojo.experimental("dojox.timing"); |
| 3 |
dojo.getObject("timing", true, dojox); |
| 4 |
|
| 5 |
dojox.timing.Timer = function( interval){ |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
this.timer = null; |
| 12 |
this.isRunning = false; |
| 13 |
this.interval = interval; |
| 14 |
|
| 15 |
this.onStart = null; |
| 16 |
this.onStop = null; |
| 17 |
}; |
| 18 |
|
| 19 |
dojo.extend(dojox.timing.Timer, { |
| 20 |
onTick: function(){ |
| 21 |
|
| 22 |
|
| 23 |
}, |
| 24 |
|
| 25 |
setInterval: function(interval){ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
if (this.isRunning){ |
| 31 |
window.clearInterval(this.timer); |
| 32 |
} |
| 33 |
this.interval = interval; |
| 34 |
if (this.isRunning){ |
| 35 |
this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval); |
| 36 |
} |
| 37 |
}, |
| 38 |
|
| 39 |
start: function(){ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
if (typeof this.onStart == "function"){ |
| 47 |
this.onStart(); |
| 48 |
} |
| 49 |
this.isRunning = true; |
| 50 |
this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval); |
| 51 |
}, |
| 52 |
|
| 53 |
stop: function(){ |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
if (typeof this.onStop == "function"){ |
| 59 |
this.onStop(); |
| 60 |
} |
| 61 |
this.isRunning = false; |
| 62 |
window.clearInterval(this.timer); |
| 63 |
} |
| 64 |
}); |
| 65 |
return dojox.timing; |
| 66 |
}); |