|
|
@@ -58,13 +58,13 @@
|
|
|
const FileReader = window.FileReader;
|
|
|
const Blob = window.Blob;
|
|
|
const console = window.console;
|
|
|
- const warn = (console && console.warn) || (() => { });
|
|
|
+ const warn = (console && console.warn && ((...args) => console.warn(...args))) || (() => { });
|
|
|
|
|
|
const observers = new Map();
|
|
|
const observedElements = new Map();
|
|
|
|
|
|
- addEventListener.call(window, LOAD_DEFERRED_IMAGES_START_EVENT, () => loadDeferredImagesStart());
|
|
|
- addEventListener.call(window, LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_START_EVENT, () => loadDeferredImagesStart(true));
|
|
|
+ addEventListener(LOAD_DEFERRED_IMAGES_START_EVENT, () => loadDeferredImagesStart());
|
|
|
+ addEventListener(LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_START_EVENT, () => loadDeferredImagesStart(true));
|
|
|
|
|
|
function loadDeferredImagesStart(keepZoomLevel) {
|
|
|
const scrollingElement = document.scrollingElement || document.documentElement;
|
|
|
@@ -108,20 +108,20 @@
|
|
|
const result = new Image(...arguments);
|
|
|
result.__defineSetter__("src", function (value) {
|
|
|
image.src = value;
|
|
|
- dispatchEvent.call(window, new CustomEvent(LOAD_IMAGE_EVENT, { detail: image.src }));
|
|
|
+ dispatchEvent(new CustomEvent(LOAD_IMAGE_EVENT, { detail: image.src }));
|
|
|
});
|
|
|
result.__defineGetter__("src", function () {
|
|
|
return image.src;
|
|
|
});
|
|
|
result.__defineSetter__("srcset", function (value) {
|
|
|
- dispatchEvent.call(window, new CustomEvent(LOAD_IMAGE_EVENT));
|
|
|
+ dispatchEvent(new CustomEvent(LOAD_IMAGE_EVENT));
|
|
|
image.srcset = value;
|
|
|
});
|
|
|
result.__defineGetter__("srcset", function () {
|
|
|
return image.srcset;
|
|
|
});
|
|
|
image.onload = image.onloadend = image.onerror = event => {
|
|
|
- dispatchEvent.call(window, new CustomEvent(IMAGE_LOADED_EVENT, { detail: image.src }));
|
|
|
+ dispatchEvent(new CustomEvent(IMAGE_LOADED_EVENT, { detail: image.src }));
|
|
|
result.dispatchEvent(new UIEvent(event.type, event));
|
|
|
};
|
|
|
if (image.decode) {
|
|
|
@@ -150,8 +150,7 @@
|
|
|
document.documentElement.style.setProperty("transform-origin", (zoomFactorX < 1 ? "50%" : "0") + " " + (zoomFactorY < 1 ? "50%" : "0") + " 0", "important");
|
|
|
document.documentElement.style.setProperty("transform", "scale3d(" + zoomFactor + ", " + zoomFactor + ", 1)", "important");
|
|
|
document.documentElement.style.setProperty("min-height", (100 / zoomFactor) + "vh", "important");
|
|
|
- dispatchEvent.call(window, new UIEvent("resize"));
|
|
|
- dispatchEvent.call(window, new Event("scroll"));
|
|
|
+ dispatchResizeEvent();
|
|
|
if (keepZoomLevel) {
|
|
|
document.documentElement.style.setProperty("-sf-transform", transform, transformPriority);
|
|
|
document.documentElement.style.setProperty("-sf-transform-origin", transformOrigin, transformOriginPriority);
|
|
|
@@ -163,8 +162,7 @@
|
|
|
}
|
|
|
}
|
|
|
if (!keepZoomLevel) {
|
|
|
- dispatchEvent.call(window, new UIEvent("resize"));
|
|
|
- dispatchEvent.call(window, new Event("scroll"));
|
|
|
+ dispatchResizeEvent();
|
|
|
const docBoundingRect = scrollingElement.getBoundingClientRect();
|
|
|
[...observers].forEach(([intersectionObserver, observer]) => {
|
|
|
const rootBoundingRect = observer.options && observer.options.root && observer.options.root.getBoundingClientRect();
|
|
|
@@ -183,9 +181,9 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- addEventListener.call(window, LOAD_DEFERRED_IMAGES_END_EVENT, () => loadDeferredImagesEnd());
|
|
|
- addEventListener.call(window, LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_END_EVENT, () => loadDeferredImagesEnd(true));
|
|
|
- addEventListener.call(window, LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT, () => {
|
|
|
+ addEventListener(LOAD_DEFERRED_IMAGES_END_EVENT, () => loadDeferredImagesEnd());
|
|
|
+ addEventListener(LOAD_DEFERRED_IMAGES_KEEP_ZOOM_LEVEL_END_EVENT, () => loadDeferredImagesEnd(true));
|
|
|
+ addEventListener(LOAD_DEFERRED_IMAGES_RESET_ZOOM_LEVEL_END_EVENT, () => {
|
|
|
const transform = document.documentElement.style.getPropertyValue("-sf-transform");
|
|
|
const transformPriority = document.documentElement.style.getPropertyPriority("-sf-transform");
|
|
|
const transformOrigin = document.documentElement.style.getPropertyValue("-sf-transform-origin");
|
|
|
@@ -226,12 +224,11 @@
|
|
|
delete window._singleFileImage;
|
|
|
}
|
|
|
if (!keepZoomLevel) {
|
|
|
- dispatchEvent.call(window, new UIEvent("resize"));
|
|
|
- dispatchEvent.call(window, new Event("scroll"));
|
|
|
+ dispatchResizeEvent();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- addEventListener.call(window, BLOCK_COOKIES_START_EVENT, () => {
|
|
|
+ addEventListener(BLOCK_COOKIES_START_EVENT, () => {
|
|
|
try {
|
|
|
document.__defineGetter__("cookie", () => { throw new Error("document.cookie temporary blocked by SingleFile"); });
|
|
|
} catch (error) {
|
|
|
@@ -239,11 +236,11 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- addEventListener.call(window, BLOCK_COOKIES_END_EVENT, () => {
|
|
|
+ addEventListener(BLOCK_COOKIES_END_EVENT, () => {
|
|
|
delete document.cookie;
|
|
|
});
|
|
|
|
|
|
- addEventListener.call(window, BLOCK_STORAGE_START_EVENT, () => {
|
|
|
+ addEventListener(BLOCK_STORAGE_START_EVENT, () => {
|
|
|
if (!window._singleFile_localStorage) {
|
|
|
window._singleFile_localStorage = window.localStorage;
|
|
|
window.__defineGetter__("localStorage", () => { throw new Error("localStorage temporary blocked by SingleFile"); });
|
|
|
@@ -254,7 +251,7 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- addEventListener.call(window, BLOCK_STORAGE_END_EVENT, () => {
|
|
|
+ addEventListener(BLOCK_STORAGE_END_EVENT, () => {
|
|
|
if (window._singleFile_localStorage) {
|
|
|
delete window.localStorage;
|
|
|
window.localStorage = window._singleFile_localStorage;
|
|
|
@@ -272,7 +269,7 @@
|
|
|
let warningFontFaceDisplayed;
|
|
|
window.FontFace = function () {
|
|
|
if (!warningFontFaceDisplayed) {
|
|
|
- warn.call(console, "SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
|
+ warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
|
warningFontFaceDisplayed = true;
|
|
|
}
|
|
|
const detail = {};
|
|
|
@@ -291,10 +288,10 @@
|
|
|
reader.readAsDataURL(new Blob([detail.src]));
|
|
|
reader.addEventListener("load", () => {
|
|
|
detail.src = "url(" + reader.result + ")";
|
|
|
- dispatchEvent.call(window, new CustomEvent(NEW_FONT_FACE_EVENT, { detail }));
|
|
|
+ dispatchEvent(new CustomEvent(NEW_FONT_FACE_EVENT, { detail }));
|
|
|
});
|
|
|
} else {
|
|
|
- dispatchEvent.call(window, new CustomEvent(NEW_FONT_FACE_EVENT, { detail }));
|
|
|
+ dispatchEvent(new CustomEvent(NEW_FONT_FACE_EVENT, { detail }));
|
|
|
}
|
|
|
return new FontFace(...arguments);
|
|
|
};
|
|
|
@@ -306,7 +303,7 @@
|
|
|
let warningIntersectionObserverDisplayed;
|
|
|
window.IntersectionObserver = function () {
|
|
|
if (!warningIntersectionObserverDisplayed) {
|
|
|
- warn.call(console, "SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
|
+ warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
|
warningIntersectionObserverDisplayed = true;
|
|
|
}
|
|
|
const intersectionObserver = new IntersectionObserver(...arguments);
|
|
|
@@ -347,4 +344,13 @@
|
|
|
window.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
|
|
|
}
|
|
|
|
|
|
+ function dispatchResizeEvent() {
|
|
|
+ try {
|
|
|
+ dispatchEvent(new UIEvent("resize"));
|
|
|
+ document.dispatchEvent(new Event("scroll", { bubbles: true }));
|
|
|
+ } catch (error) {
|
|
|
+ // ignored
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
})();
|