Преглед на файлове

fixed conflict with SingleFileZ

Former-commit-id: 27e8d933e135958ae184a4b64af3cb2e4bb07383
Gildas преди 6 години
родител
ревизия
a538fccedb
променени са 1 файла, в които са добавени 18 реда и са изтрити 17 реда
  1. 18 17
      lib/hooks/content/content-hooks-frames-web.js

+ 18 - 17
lib/hooks/content/content-hooks-frames-web.js

@@ -283,19 +283,18 @@
 
 	if (window.IntersectionObserver) {
 		const IntersectionObserver = window.IntersectionObserver;
-		const observeIntersection = IntersectionObserver.prototype.observe;
-		const unobserveIntersection = IntersectionObserver.prototype.unobserve;
 		let warningIntersectionObserverDisplayed;
-		if (observeIntersection && unobserveIntersection) {
-			window.IntersectionObserver = function () {
-				if (!warningIntersectionObserverDisplayed) {
-					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);
-				const callback = arguments[0];
-				const options = arguments[1];
-				intersectionObserver.id = observers.size;
+		window.IntersectionObserver = function () {
+			if (!warningIntersectionObserverDisplayed) {
+				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);
+			const observeIntersection = IntersectionObserver.prototype.observe || intersectionObserver.observe;
+			const unobserveIntersection = IntersectionObserver.prototype.unobserve || intersectionObserver.unobserve;
+			const callback = arguments[0];
+			const options = arguments[1];
+			if (observeIntersection) {
 				intersectionObserver.observe = function (targetElement) {
 					let targetElements = observedElements.get(intersectionObserver);
 					if (!targetElements) {
@@ -305,6 +304,8 @@
 					targetElements.push(targetElement);
 					return observeIntersection.call(intersectionObserver, targetElement);
 				};
+			}
+			if (unobserveIntersection) {
 				intersectionObserver.unobserve = function (targetElement) {
 					let targetElements = observedElements.get(intersectionObserver);
 					if (targetElements) {
@@ -316,11 +317,11 @@
 					}
 					return unobserveIntersection.call(intersectionObserver, targetElement);
 				};
-				observers.set(intersectionObserver, { callback, options });
-				return intersectionObserver;
-			};
-			window.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
-		}
+			}
+			observers.set(intersectionObserver, { callback, options });
+			return intersectionObserver;
+		};
+		window.IntersectionObserver.toString = function () { return "function IntersectionObserver() { [native code] }"; };
 	}
 
 })();