This repository has been archived by the owner on Mar 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
animationFrame.h5ive.js
80 lines (65 loc) · 1.72 KB
/
animationFrame.h5ive.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
/*! animationFrame.h5ive.js | (c) Kyle Simpson | MIT License: http://getify.mit-license.org */
(function(h5){
if (!h5) throw new Error("animationFrame.h5ive: core.h5ive required.");
var rAF = (window.requestAnimationFrame || window.msRequestAnimationFrame ||
window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
window.oRequestAnimationFrame),
cAF = (window.cancelAnimationFrame ||
window.msCancelAnimationFrame || window.msCancelRequestAnimationFrame ||
window.mozCancelAnimationFrame || window.mozCancelRequestAnimationFrame ||
window.webkitCancelAnimationFrame || window.webkitCancelRequestAnimationFrame ||
window.oCancelAnimationFrame || window.oCancelRequestAnimationFrame),
publicAPI, q_ids = {}
;
function qID(){
var id;
do {
id = Math.floor(Math.random() * 1E9);
} while (id in q_ids);
return id;
}
function queue(cb) {
var qid = qID();
q_ids[qid] = rAF(function(){
delete q_ids[qid];
cb.apply(publicAPI,arguments);
});
return qid;
}
function queueAfter(cb) {
var qid;
qid = queue(function(){
// do our own rAF call here because we want to re-use the same `qid` for both frames
q_ids[qid] = rAF(function(){
delete q_ids[qid];
cb.apply(publicAPI,arguments);
});
});
return qid;
}
function cancel(qID) {
if (qID in q_ids) {
cAF(q_ids[qID]);
delete q_ids[qID];
}
return publicAPI;
}
function unsupported() {
throw new Error("'requestAnimationFrame' not supported.");
}
if (rAF && cAF) {
publicAPI = {
queue: queue,
queueAfter: queueAfter,
cancel: cancel
};
}
else {
publicAPI = {
queue: unsupported,
queueAfter: unsupported,
cancel: unsupported
};
}
h5.animationFrame = publicAPI;
})(this.h5);