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