소스 검색

don't trigger observers in external frames

Gildas 4 년 전
부모
커밋
3bc97355e0
1개의 변경된 파일18개의 추가작업 그리고 15개의 파일을 삭제
  1. 18 15
      lib/single-file/processors/hooks/content/content-hooks-frames-web.js

+ 18 - 15
lib/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -167,21 +167,24 @@
 		if (!keepZoomLevel) {
 			dispatchResizeEvent();
 			const docBoundingRect = scrollingElement.getBoundingClientRect();
-			[...observers].forEach(([intersectionObserver, observer]) => {
-				const getBoundingClientRectDefined = observer.options && observer.options.root && observer.options.root.getBoundingClientRect;
-				const rootBoundingRect = getBoundingClientRectDefined && observer.options.root.getBoundingClientRect();
-				const targetElements = observedElements.get(intersectionObserver);
-				if (targetElements) {
-					observer.callback(targetElements.map(target => {
-						const boundingClientRect = target.getBoundingClientRect();
-						const isIntersecting = true;
-						const intersectionRatio = 1;
-						const rootBounds = getBoundingClientRectDefined ? rootBoundingRect : docBoundingRect;
-						const time = 0;
-						return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
-					}), intersectionObserver);
-				}
-			});
+			if (window == window.top) {
+				[...observers].forEach(([intersectionObserver, observer]) => {
+					const getBoundingClientRectDefined = observer.options && observer.options.root && observer.options.root.getBoundingClientRect;
+					const rootBoundingRect = getBoundingClientRectDefined && observer.options.root.getBoundingClientRect();
+					const targetElements = observedElements.get(intersectionObserver);
+					if (targetElements) {
+						const params = targetElements.map(target => {
+							const boundingClientRect = target.getBoundingClientRect();
+							const isIntersecting = true;
+							const intersectionRatio = 1;
+							const rootBounds = getBoundingClientRectDefined ? rootBoundingRect : docBoundingRect;
+							const time = 0;
+							return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
+						});
+						observer.callback(params, intersectionObserver);
+					}
+				});
+			}
 		}
 	}