|
|
@@ -50,9 +50,12 @@ this.hooks = this.hooks || (() => {
|
|
|
};
|
|
|
|
|
|
const FontFace = window.FontFace;
|
|
|
- console.warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
|
+ let warningFontFaceDisplayed;
|
|
|
window.__defineGetter__("FontFace", () => new Proxy(FontFace, {
|
|
|
construct(FontFace, argumentsList) {
|
|
|
+ if (!warningFontFaceDisplayed) {
|
|
|
+ console.warn("SingleFile is hooking the FontFace constructor to get font URLs."); // eslint-disable-line no-console
|
|
|
+ }
|
|
|
const detail = {};
|
|
|
detail["font-family"] = argumentsList[0];
|
|
|
detail.src = argumentsList[1];
|
|
|
@@ -65,14 +68,19 @@ this.hooks = this.hooks || (() => {
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
+ const LOAD_OBSERVED_ELEMENTS_EVENT = "single-file-load-observed-elements";
|
|
|
+
|
|
|
const IntersectionObserver = window.IntersectionObserver;
|
|
|
const observeIntersection = IntersectionObserver.prototype.observe;
|
|
|
const unobserveIntersection = IntersectionObserver.prototype.unobserve;
|
|
|
const observedElements = new Map();
|
|
|
const observers = new Map();
|
|
|
- console.warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
|
+ let warningIntersectionObserverDisplayed;
|
|
|
window.__defineGetter__("IntersectionObserver", () => new Proxy(IntersectionObserver, {
|
|
|
construct(IntersectionObserver, argumentsList) {
|
|
|
+ if (!warningIntersectionObserverDisplayed) {
|
|
|
+ console.warn("SingleFile is hooking the IntersectionObserver API to detect and load deferred images."); // eslint-disable-line no-console
|
|
|
+ }
|
|
|
const intersectionObserver = new IntersectionObserver(...argumentsList);
|
|
|
const callback = argumentsList[0];
|
|
|
const options = argumentsList[1];
|
|
|
@@ -102,7 +110,7 @@ this.hooks = this.hooks || (() => {
|
|
|
}
|
|
|
}));
|
|
|
window.__defineSetter__("IntersectionObserver", () => { });
|
|
|
- addEventListener("single-file-load-observed-elements", () => {
|
|
|
+ addEventListener(LOAD_OBSERVED_ELEMENTS_EVENT, () => {
|
|
|
Array.from(observers).forEach(([intersectionObserver, observer]) => {
|
|
|
observer.callback(observedElements.get(intersectionObserver).map(target => {
|
|
|
const boundingClientRect = target.getBoundingClientRect();
|