Browse Source

remove lazy loaded src when the resource is loaded

Gildas 5 years ago
parent
commit
14f101d931
1 changed files with 7 additions and 0 deletions
  1. 7 0
      lib/single-file/processors/lazy/content/content-lazy-loader.js

+ 7 - 0
lib/single-file/processors/lazy/content/content-lazy-loader.js

@@ -66,6 +66,7 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 					const updated = mutations.filter(mutation => {
 						if (mutation.attributeName == "src") {
 							mutation.target.setAttribute(singlefile.lib.helper.LAZY_SRC_ATTRIBUTE_NAME, mutation.target.src);
+							mutation.target.addEventListener("load", onResourceLoad);
 						}
 						if (mutation.attributeName == "src" || mutation.attributeName == "srcset" || mutation.target.tagName == "SOURCE") {
 							return mutation.target.className != SINGLE_FILE_UI_ELEMENT_CLASS;
@@ -94,6 +95,12 @@ this.singlefile.lib.processors.lazy.content.loader = this.singlefile.lib.process
 				frames.loadDeferredImagesStart(options);
 			}
 
+			function onResourceLoad(event) {
+				const element = event.target;
+				element.removeAttribute(singlefile.lib.helper.LAZY_SRC_ATTRIBUTE_NAME);
+				element.removeEventListener(onResourceLoad);
+			}
+
 			async function onImageLoadEvent(event) {
 				loadingImages = true;
 				maxTimeoutId = await deferForceLazyLoadEnd(timeoutId, idleTimeoutId, maxTimeoutId, observer, options, cleanupAndResolve);