add window.requestIdleCallback polyfill for safari
This commit is contained in:
parent
0fcc2d1d66
commit
31ef788e02
19
js/common.js
19
js/common.js
|
@ -29,6 +29,25 @@ function $$(query) {
|
|||
return document.querySelectorAll(query);
|
||||
}
|
||||
|
||||
// polyfill for safari https://raw.githubusercontent.com/pladaria/requestidlecallback-polyfill/master/index.js
|
||||
window.requestIdleCallback =
|
||||
window.requestIdleCallback ||
|
||||
function (callback) {
|
||||
const start = Date.now();
|
||||
return setTimeout(() => {
|
||||
callback({
|
||||
didTimeout: false,
|
||||
timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
|
||||
},
|
||||
);
|
||||
}, 1);
|
||||
};
|
||||
|
||||
window.cancelIdleCallback =
|
||||
window.cancelIdleCallback ||
|
||||
function (id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
|
||||
Element.prototype.hasClassName = function(className) {
|
||||
return this.classList.contains(className);
|
||||
|
|
Loading…
Reference in New Issue