|
@@ -283,19 +283,18 @@
|
|
|
|
|
|
|
|
if (window.IntersectionObserver) {
|
|
if (window.IntersectionObserver) {
|
|
|
const IntersectionObserver = window.IntersectionObserver;
|
|
const IntersectionObserver = window.IntersectionObserver;
|
|
|
- const observeIntersection = IntersectionObserver.prototype.observe;
|
|
|
|
|
- const unobserveIntersection = IntersectionObserver.prototype.unobserve;
|
|
|
|
|
let warningIntersectionObserverDisplayed;
|
|
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) {
|
|
intersectionObserver.observe = function (targetElement) {
|
|
|
let targetElements = observedElements.get(intersectionObserver);
|
|
let targetElements = observedElements.get(intersectionObserver);
|
|
|
if (!targetElements) {
|
|
if (!targetElements) {
|
|
@@ -305,6 +304,8 @@
|
|
|
targetElements.push(targetElement);
|
|
targetElements.push(targetElement);
|
|
|
return observeIntersection.call(intersectionObserver, targetElement);
|
|
return observeIntersection.call(intersectionObserver, targetElement);
|
|
|
};
|
|
};
|
|
|
|
|
+ }
|
|
|
|
|
+ if (unobserveIntersection) {
|
|
|
intersectionObserver.unobserve = function (targetElement) {
|
|
intersectionObserver.unobserve = function (targetElement) {
|
|
|
let targetElements = observedElements.get(intersectionObserver);
|
|
let targetElements = observedElements.get(intersectionObserver);
|
|
|
if (targetElements) {
|
|
if (targetElements) {
|
|
@@ -316,11 +317,11 @@
|
|
|
}
|
|
}
|
|
|
return unobserveIntersection.call(intersectionObserver, targetElement);
|
|
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] }"; };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
})();
|
|
})();
|