summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-04-09 10:29:42 +0300
committerAndrew Dolgov <[email protected]>2023-04-09 10:29:42 +0300
commit31ef788e02339452fa6241277e17f85067c33ba0 (patch)
treed98f197c16ab10b4203c2aee62db178e1c3c698e /js
parent0fcc2d1d662fcbc79ac341f075ae308f69665719 (diff)
add window.requestIdleCallback polyfill for safari
Diffstat (limited to 'js')
-rwxr-xr-xjs/common.js19
1 files changed, 19 insertions, 0 deletions
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);