-
Notifications
You must be signed in to change notification settings - Fork 38
/
window.polyfill.js
62 lines (59 loc) · 1.68 KB
/
window.polyfill.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
/**
* window.requestIdleCallback()
* version 0.0.0
* Browser Compatibility:
* https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback#browser_compatibility
*/
if (!window.requestIdleCallback) {
window.requestIdleCallback = function (callback, options) {
var options = options || {};
var relaxation = 1;
var timeout = options.timeout || relaxation;
var start = performance.now();
return setTimeout(function () {
callback({
get didTimeout() {
return options.timeout ? false : (performance.now() - start) - relaxation > timeout;
},
timeRemaining: function () {
return Math.max(0, relaxation + (performance.now() - start));
},
});
}, relaxation);
};
}
/**
* window.cancelIdleCallback()
* version 0.0.0
* Browser Compatibility:
* https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelIdleCallback#browser_compatibility
*/
if (!window.cancelIdleCallback) {
window.cancelIdleCallback = function (id) {
clearTimeout(id);
};
}
/**
* window.requestAnimationFrame()
* version 0.0.0
* Browser Compatibility:
* https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#browser_compatibility
*/
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function (callback) {
return window.setTimeout(function () {
callback(Date.now());
}, 1000 / 60);
};
}
/**
* window.cancelAnimationFrame()
* version 0.0.0
* Browser Compatibility:
* https://developer.mozilla.org/en-US/docs/Web/API/Window/cancelAnimationFrame#browser_compatibility
*/
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
}