forked from jeresig/env-js
/
timer.js
69 lines (58 loc) · 1.24 KB
/
timer.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* timer.js
*/
$debug("Initializing Window Timer.");
//private
var $timers = [];
window.setTimeout = function(fn, time){
var num = $timers.length;
var tfn;
if (typeof fn == 'string') {
tfn = function() {
eval(fn);
window.clearInterval(num);
};
} else {
tfn = function() {
fn();
window.clearInterval(num);
};
}
if (time === 0){
if (typeof fn == 'string')
eval(fn);
else
fn();
}
else {
$debug("Creating timer number "+num);
$timers[num] = new $env.timer(tfn, time);
$timers[num].start();
return num;
}
};
window.setInterval = function(fn, time){
var num = $timers.length;
if (typeof fn == 'string') {
var fnstr = fn;
fn = function() {
eval(fnstr);
};
}
if(time===0){
fn();
}else{
$debug("Creating timer number "+num);
$timers[num] = new $env.timer(fn, time);
$timers[num].start();
}
return num;
};
window.clearInterval = window.clearTimeout = function(num){
if ( $timers[num] ) {
$debug("Deleting timer number "+num);
$timers[num].stop();
delete $timers[num];
}
};
window.$wait = function(wait){ $env.wait(wait); }