Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lib_timer.js « js - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aadea90ba27ebb37ac1314968fa436032a1fcbb7 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
/**
 * StarLight - A client side webpage framework
 *
 * @package StarLight
 * @author Icewind <icewind (at) derideal (dot) com>
 * @copyright 2009
 * @license http://www.gnu.org/licenses/gpl.html GNU Public License
 * @url http://blacklight.metalwarp.com/starlight
 * @version 0.1
 */
OCTimer=function(callback,time,repeat,object){
	this.object=(object)?object:false;
	this.repeat=(!(repeat===undefined))?repeat:true;
	this.callback=callback;
	this.time=time;
	this.timer=0;
	this.number=OCTimer.count;
	OCTimer.count++;
	OCTimer.timers[this.number]=this;
	if(this.time){
		this.start();
	}
}

OCTimer.count=0;
OCTimer.timers=Array();

OCTimer.prototype={
	start:function(){
		this.running=true;
		eval('var func=function(){OCTimer.timers['+this.number+'].run();};');
		if(this.repeat){
			this.timer = setInterval(func, this.time);
		}else{
			this.timer = setTimeout(func, this.time);
		}
	},
	run:function(){
		if (!this.repeat){
			this.stop();
		}
		if (this.object){
			this.callback.call(this.object);
		}else{
			this.callback.call();
		}
	},
	stop:function(){
		clearInterval(this.timer);
		this.running=false;
	}
}