|
@@ -23,7 +23,6 @@
|
|
|
this.lazyLoader = this.lazyLoader || (() => {
|
|
this.lazyLoader = this.lazyLoader || (() => {
|
|
|
|
|
|
|
|
const SCRIPT_TAG_NAME = "script";
|
|
const SCRIPT_TAG_NAME = "script";
|
|
|
- const MONITORED_ATTRIBUTES = ["src", "srcset"];
|
|
|
|
|
const ATTRIBUTES_MUTATION_TYPE = "attributes";
|
|
const ATTRIBUTES_MUTATION_TYPE = "attributes";
|
|
|
const SCRIPT_BEFORE_PATH = "lib/lazy/web/web-lazy-loader-before.js";
|
|
const SCRIPT_BEFORE_PATH = "lib/lazy/web/web-lazy-loader-before.js";
|
|
|
const SCRIPT_AFTER_PATH = "lib/lazy/web/web-lazy-loader-after.js";
|
|
const SCRIPT_AFTER_PATH = "lib/lazy/web/web-lazy-loader-after.js";
|
|
@@ -36,20 +35,23 @@ this.lazyLoader = this.lazyLoader || (() => {
|
|
|
const maxTimeoutId = await setTimeout(() => {
|
|
const maxTimeoutId = await setTimeout(() => {
|
|
|
clearTimeout(timeoutId);
|
|
clearTimeout(timeoutId);
|
|
|
lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
- }, options.maxLazyLoadImagesIdleTime * 3);
|
|
|
|
|
|
|
+ }, options.maxLazyLoadImagesIdleTime * 5);
|
|
|
const observer = new MutationObserver(async mutations => {
|
|
const observer = new MutationObserver(async mutations => {
|
|
|
mutations = mutations.filter(mutation => mutation.type == ATTRIBUTES_MUTATION_TYPE);
|
|
mutations = mutations.filter(mutation => mutation.type == ATTRIBUTES_MUTATION_TYPE);
|
|
|
if (mutations.length) {
|
|
if (mutations.length) {
|
|
|
- mutations.forEach(mutation => {
|
|
|
|
|
- if (mutation.target.src) {
|
|
|
|
|
|
|
+ const updated = mutations.filter(mutation => {
|
|
|
|
|
+ if (mutation.attributeName == "src") {
|
|
|
mutation.target.setAttribute("data-lazy-loaded-src", mutation.target.src);
|
|
mutation.target.setAttribute("data-lazy-loaded-src", mutation.target.src);
|
|
|
}
|
|
}
|
|
|
|
|
+ return mutation.attributeName != "data-lazy-loaded-src";
|
|
|
});
|
|
});
|
|
|
- srcAttributeChanged = true;
|
|
|
|
|
- timeoutId = await deferLazyLoadEnd(timeoutId, maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
|
|
|
|
+ if (updated.length) {
|
|
|
|
|
+ srcAttributeChanged = true;
|
|
|
|
|
+ timeoutId = await deferLazyLoadEnd(timeoutId, maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- observer.observe(document, { attributeFilter: MONITORED_ATTRIBUTES, subtree: true, childList: true, attributes: true });
|
|
|
|
|
|
|
+ observer.observe(document, { subtree: true, childList: true, attributes: true });
|
|
|
const idleTimeoutId = await setTimeout(() => {
|
|
const idleTimeoutId = await setTimeout(() => {
|
|
|
if (!srcAttributeChanged) {
|
|
if (!srcAttributeChanged) {
|
|
|
clearTimeout(timeoutId);
|
|
clearTimeout(timeoutId);
|