From 31ef788e02339452fa6241277e17f85067c33ba0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 9 Apr 2023 10:29:42 +0300 Subject: [PATCH] add window.requestIdleCallback polyfill for safari --- js/common.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/common.js b/js/common.js index b972f2376..9635ab492 100755 --- a/js/common.js +++ b/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);