|
|
@@ -53,17 +53,13 @@
|
|
|
const UIEvent = window.UIEvent;
|
|
|
const FileReader = window.FileReader;
|
|
|
const Blob = window.Blob;
|
|
|
- const requestAnimationFrame = window.requestAnimationFrame;
|
|
|
- const cancelAnimationFrame = window.cancelAnimationFrame;
|
|
|
const console = window.console;
|
|
|
const warn = (console && console.warn) || (() => { });
|
|
|
|
|
|
const observers = new Map();
|
|
|
const observedElements = new Map();
|
|
|
- let loadDeferredImages;
|
|
|
|
|
|
addEventListener.call(window, LOAD_DEFERRED_IMAGES_START_EVENT, () => {
|
|
|
- loadDeferredImages = true;
|
|
|
const scrollingElement = document.scrollingElement || document.documentElement;
|
|
|
const clientHeight = scrollingElement.clientHeight;
|
|
|
const clientWidth = scrollingElement.clientWidth;
|
|
|
@@ -154,12 +150,6 @@
|
|
|
}), intersectionObserver);
|
|
|
}
|
|
|
});
|
|
|
- if (pendingRequestAnimationFrameCalls.size) {
|
|
|
- [...pendingRequestAnimationFrameCalls].forEach(([id, callback]) => {
|
|
|
- cancelAnimationFrame(id);
|
|
|
- callback();
|
|
|
- });
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
addEventListener.call(window, LOAD_DEFERRED_IMAGES_END_EVENT, () => {
|
|
|
@@ -181,7 +171,6 @@
|
|
|
window.Image = window._singleFileImage;
|
|
|
delete window._singleFileImage;
|
|
|
}
|
|
|
- loadDeferredImages = false;
|
|
|
dispatchEvent.call(window, new UIEvent("resize"));
|
|
|
dispatchEvent.call(window, new UIEvent("scroll"));
|
|
|
});
|
|
|
@@ -222,50 +211,6 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- let warningRequestAnimationFrameDisplayed;
|
|
|
- const pendingRequestAnimationFrameCalls = new Map();
|
|
|
- let lastTimestamp = 0;
|
|
|
- let errorDetected;
|
|
|
- window.requestAnimationFrame = function (callback) {
|
|
|
- if (!warningRequestAnimationFrameDisplayed) {
|
|
|
- warn.call(console, "SingleFile is hooking the requestAnimationFrame and cancelAnimationFrame functions to load deferred images in background tabs."); // eslint-disable-line no-console
|
|
|
- warningRequestAnimationFrameDisplayed = true;
|
|
|
- }
|
|
|
- let requestId;
|
|
|
- if (loadDeferredImages && !errorDetected) {
|
|
|
- try {
|
|
|
- requestId = 0;
|
|
|
- callback(lastTimestamp);
|
|
|
- } catch (error) {
|
|
|
- errorDetected = true;
|
|
|
- requestId = requestAnimationFrame(timestamp => {
|
|
|
- lastTimestamp = timestamp;
|
|
|
- callback(timestamp);
|
|
|
- });
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (!loadDeferredImages) {
|
|
|
- errorDetected = false;
|
|
|
- }
|
|
|
- requestId = requestAnimationFrame(timestamp => {
|
|
|
- pendingRequestAnimationFrameCalls.delete(requestId);
|
|
|
- lastTimestamp = timestamp;
|
|
|
- callback(timestamp);
|
|
|
- });
|
|
|
- if (!loadDeferredImages || pendingRequestAnimationFrameCalls.length < 128) {
|
|
|
- pendingRequestAnimationFrameCalls.set(requestId, callback);
|
|
|
- }
|
|
|
- }
|
|
|
- return requestId;
|
|
|
- };
|
|
|
- window.requestAnimationFrame.toString = function () { return "requestAnimationFrame() { [native code] }"; };
|
|
|
-
|
|
|
- window.cancelAnimationFrame = function (requestId) {
|
|
|
- pendingRequestAnimationFrameCalls.delete(requestId);
|
|
|
- return cancelAnimationFrame(requestId);
|
|
|
- };
|
|
|
- window.cancelAnimationFrame.toString = function () { return "cancelAnimationFrame() { [native code] }"; };
|
|
|
-
|
|
|
if (window.FontFace) {
|
|
|
const FontFace = window.FontFace;
|
|
|
let warningFontFaceDisplayed;
|