Răsfoiți Sursa

merged listeners

Former-commit-id: 64005dbec15c4df7d51e7ec65e82b01a11558c99
Gildas 6 ani în urmă
părinte
comite
b9cd372fc8
1 a modificat fișierele cu 20 adăugiri și 27 ștergeri
  1. 20 27
      lib/hooks/content/content-hooks-frames-web.js

+ 20 - 27
lib/hooks/content/content-hooks-frames-web.js

@@ -49,6 +49,7 @@
 	let loadDeferredImages;
 
 	addEventListener(LOAD_DEFERRED_IMAGES_START_EVENT, () => {
+		loadDeferredImages = true;
 		const scrollingElement = document.scrollingElement || document.documentElement;
 		const clientHeight = scrollingElement.clientHeight;
 		const clientWidth = scrollingElement.clientWidth;
@@ -121,6 +122,24 @@
 		}
 		dispatchEvent(new UIEvent("resize"));
 		dispatchEvent(new UIEvent("scroll"));
+		const docBoundingRect = scrollingElement.getBoundingClientRect();
+		Array.from(observers, ([intersectionObserver, observer]) => {
+			const rootBoundingRect = observer.options.root && observer.options.root.getBoundingClientRect();
+			observer.callback(observedElements.get(intersectionObserver).map(target => {
+				const boundingClientRect = target.getBoundingClientRect();
+				const isIntersecting = true;
+				const intersectionRatio = 1;
+				const rootBounds = observer.options && observer.options.root ? rootBoundingRect : docBoundingRect;
+				const time = 0;
+				return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
+			}), intersectionObserver);
+		});
+		if (pendingRequestAnimationFrameCalls.size) {
+			Array.from(pendingRequestAnimationFrameCalls).forEach(([id, callback]) => {
+				cancelAnimationFrame(id);
+				callback();
+			});
+		}
 	});
 
 
@@ -143,6 +162,7 @@
 			window.Image = window._singleFileImage;
 			delete window._singleFileImage;
 		}
+		loadDeferredImages = false;
 		dispatchEvent(new UIEvent("resize"));
 		dispatchEvent(new UIEvent("scroll"));
 	});
@@ -177,33 +197,6 @@
 		}
 	});
 
-	addEventListener(LOAD_DEFERRED_IMAGES_START_EVENT, () => {
-		loadDeferredImages = true;
-		const scrollingElement = document.scrollingElement || document.documentElement;
-		const docBoundingRect = scrollingElement.getBoundingClientRect();
-		Array.from(observers, ([intersectionObserver, observer]) => {
-			const rootBoundingRect = observer.options.root && observer.options.root.getBoundingClientRect();
-			observer.callback(observedElements.get(intersectionObserver).map(target => {
-				const boundingClientRect = target.getBoundingClientRect();
-				const isIntersecting = true;
-				const intersectionRatio = 1;
-				const rootBounds = observer.options && observer.options.root ? rootBoundingRect : docBoundingRect;
-				const time = 0;
-				return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
-			}), intersectionObserver);
-		});
-		if (pendingRequestAnimationFrameCalls.size) {
-			Array.from(pendingRequestAnimationFrameCalls).forEach(([id, callback]) => {
-				cancelAnimationFrame(id);
-				callback();
-			});
-		}
-	});
-
-	addEventListener(LOAD_DEFERRED_IMAGES_END_EVENT, () => {
-		loadDeferredImages = false;
-	});
-
 	let warningRequestAnimationFrameDisplayed;
 	const pendingRequestAnimationFrameCalls = new Map();
 	let lastTimestamp = 0;