Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.timing._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.timing._base"] = true;
3
dojo.provide("dojox.timing._base");
4
dojo.experimental("dojox.timing");
5
 
6
dojox.timing.Timer = function(/*int*/ interval){
7
	// summary: Timer object executes an "onTick()" method repeatedly at a specified interval.
8
	//			repeatedly at a given interval.
9
	// interval: Interval between function calls, in milliseconds.
10
	this.timer = null;
11
	this.isRunning = false;
12
	this.interval = interval;
13
 
14
	this.onStart = null;
15
	this.onStop = null;
16
};
17
 
18
dojo.extend(dojox.timing.Timer, {
19
	onTick : function(){
20
		// summary: Method called every time the interval passes.  Override to do something useful.
21
	},
22
 
23
	setInterval : function(interval){
24
		// summary: Reset the interval of a timer, whether running or not.
25
		// interval: New interval, in milliseconds.
26
		if (this.isRunning){
27
			window.clearInterval(this.timer);
28
		}
29
		this.interval = interval;
30
		if (this.isRunning){
31
			this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
32
		}
33
	},
34
 
35
	start : function(){
36
		// summary: Start the timer ticking.
37
		// description: Calls the "onStart()" handler, if defined.
38
		// 				Note that the onTick() function is not called right away,
39
		//				only after first interval passes.
40
		if (typeof this.onStart == "function"){
41
			this.onStart();
42
		}
43
		this.isRunning = true;
44
		this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
45
	},
46
 
47
	stop : function(){
48
		// summary: Stop the timer.
49
		// description: Calls the "onStop()" handler, if defined.
50
		if (typeof this.onStop == "function"){
51
			this.onStop();
52
		}
53
		this.isRunning = false;
54
		window.clearInterval(this.timer);
55
	}
56
});
57
 
58
}