add window.requestIdleCallback polyfill for safari

This commit is contained in:
Andrew Dolgov 2023-04-09 10:29:42 +03:00
parent 0fcc2d1d66
commit 31ef788e02
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
1 changed files with 19 additions and 0 deletions

View File

@ -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);