This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
95 lines (84 loc) · 2.13 KB
/
index.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(function(globals) {
'use strict';
// Delayer
// -------
var Delayer = {
setTimeout: function(name, time, handler) {
var handle, wrappedHandler,
_this = this;
if (this.timeouts == null) {
this.timeouts = {};
}
this.clearTimeout(name);
wrappedHandler = function() {
delete _this.timeouts[name];
return handler();
};
handle = setTimeout(wrappedHandler, time);
this.timeouts[name] = handle;
return handle;
},
clearTimeout: function(name) {
if (!(this.timeouts && (this.timeouts[name] != null))) {
return;
}
clearTimeout(this.timeouts[name]);
delete this.timeouts[name];
},
clearAllTimeouts: function() {
var handle, name, _ref;
if (!this.timeouts) {
return;
}
_ref = this.timeouts;
for (name in _ref) {
handle = _ref[name];
this.clearTimeout(name);
}
},
setInterval: function(name, time, handler) {
var handle;
this.clearInterval(name);
if (this.intervals == null) {
this.intervals = {};
}
handle = setInterval(handler, time);
this.intervals[name] = handle;
return handle;
},
clearInterval: function(name) {
if (!(this.intervals && this.intervals[name])) {
return;
}
clearInterval(this.intervals[name]);
delete this.intervals[name];
},
clearAllIntervals: function() {
var handle, name, _ref;
if (!this.intervals) {
return;
}
_ref = this.intervals;
for (name in _ref) {
handle = _ref[name];
this.clearInterval(name);
}
},
clearDelayed: function() {
this.clearAllTimeouts();
this.clearAllIntervals();
}
};
if (typeof Object.freeze === "function") {
Object.freeze(Delayer);
}
if (typeof define !== 'undefined' && define.amd) {
define([], function () {
return Delayer;
}); // RequireJS
} else if (typeof module !== 'undefined' && module.exports) {
module.exports = Delayer; // CommonJS
} else {
globals.Delayer = Delayer; // <script>
}
})(this);