Debian Codegraph @

dojox/timing/_base.js

raw symbols SCIP
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(/*int*/ interval){
6 // summary:
7 // Timer object executes an "onTick()" method repeatedly at a specified interval.
8 // repeatedly at a given interval.
9 // interval:
10 // Interval between function calls, in milliseconds.
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 // summary:
22 // Method called every time the interval passes. Override to do something useful.
23 },
24
25 setInterval: function(interval){
26 // summary:
27 // Reset the interval of a timer, whether running or not.
28 // interval:
29 // New interval, in milliseconds.
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 // summary:
41 // Start the timer ticking.
42 // description:
43 // Calls the "onStart()" handler, if defined.
44 // Note that the onTick() function is not called right away,
45 // only after first interval passes.
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 // summary:
55 // Stop the timer.
56 // description:
57 // Calls the "onStop()" handler, if defined.
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 });