Bladeren bron

moved warnings

Gildas 7 jaren geleden
bovenliggende
commit
6ef1dfb34b
2 gewijzigde bestanden met toevoegingen van 15 en 4 verwijderingen
  1. 11 3
      lib/hooks/hooks.js
  2. 4 1
      lib/lazy/web/web-lazy-loader-before.js

+ 11 - 3
lib/hooks/hooks.js

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

+ 4 - 1
lib/lazy/web/web-lazy-loader-before.js

@@ -18,10 +18,12 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global screen, window, document, dispatchEvent, UIEvent */
+/* global screen, window, document, dispatchEvent, UIEvent, CustomEvent */
 
 (() => {
 
+	const LOAD_OBSERVED_ELEMENTS_EVENT = "single-file-load-observed-elements";
+
 	window.__defineGetter__("innerHeight", () => document.documentElement.scrollHeight);
 	window.__defineGetter__("innerWidth", () => document.documentElement.scrollWidth);
 	document.documentElement.__defineGetter__("clientHeight", () => document.documentElement.scrollHeight);
@@ -30,5 +32,6 @@
 	screen.__defineGetter__("width", () => document.documentElement.scrollWidth);
 	dispatchEvent(new UIEvent("resize"));
 	dispatchEvent(new UIEvent("scroll"));
+	dispatchEvent(new CustomEvent(LOAD_OBSERVED_ELEMENTS_EVENT));
 
 })();