Răsfoiți Sursa

refactored frames function

Gildas 7 ani în urmă
părinte
comite
8a458c5a54
1 a modificat fișierele cu 12 adăugiri și 35 ștergeri
  1. 12 35
      lib/single-file/single-file-core.js

+ 12 - 35
lib/single-file/single-file-core.js

@@ -349,7 +349,7 @@ const SingleFileCore = (() => {
 					style.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
 				}
 			});
-										}
+		}
 
 		removeHiddenElements() {
 			this.doc.querySelectorAll("[" + REMOVED_CONTENT_ATTRIBUTE_NAME + "]").forEach(element => element.remove());
@@ -449,25 +449,14 @@ const SingleFileCore = (() => {
 			await Promise.all(frameElements.map(async (frameElement, frameIndex) => {
 				const frameWindowId = (this.options.windowId || "0") + "." + frameIndex;
 				const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
+				const setFrameEmptySrc = frameElement => frameElement.setAttribute(frameElement.tagName == "OBJECT" ? "data" : "src", EMPTY_DATA_URI);
 				if (frameData) {
 					if (initialization) {
-						const options = {
-							insertSingleFileComment: false,
-							insertFaviconLink: false,
-							url: frameData.baseURI,
-							windowId: frameWindowId,
-							removeHiddenElements: this.options.removeHiddenElements,
-							removeUnusedCSSRules: this.options.removeUnusedCSSRules,
-							jsEnabled: this.options.jsEnabled,
-							removeScripts: this.options.removeScripts,
-							saveRawPage: this.options.saveRawPage,
-							compressHTML: this.options.compressHTML,
-							compressCSS: this.options.compressCSS,
-							lazyLoadImages: this.options.lazyLoadImages,
-							framesData: this.options.framesData,
-							maxResourceSize: this.options.maxResourceSize,
-							maxResourceSizeEnabled: this.options.maxResourceSizeEnabled
-						};
+						const options = Object.create(this.options);
+						options.insertSingleFileComment = false;
+						options.insertFaviconLink = false;
+						options.url = frameData.baseURI;
+						options.windowId = frameWindowId;
 						if (frameData.content) {
 							frameData.processor = new PageProcessor(options);
 							frameData.frameElement = frameElement;
@@ -475,27 +464,15 @@ const SingleFileCore = (() => {
 							return frameData.processor.initialize();
 						}
 					} else {
-						if (frameElement.tagName == "OBJECT") {
-							frameElement.setAttribute("data", "about:blank");
-						} else {
-							frameElement.setAttribute("src", "about:blank");
-						}
+						setFrameEmptySrc(frameElement);
 						if (frameData.processor) {
 							const pageData = await frameData.processor.getPageData();
-							if (frameElement.tagName == "OBJECT") {
-								frameElement.setAttribute("data", "data:text/html," + pageData.content);
-							} else {
-								frameElement.setAttribute("srcdoc", pageData.content);
-								frameElement.sandbox = true;
-							}
+							frameElement.setAttribute(frameElement.tagName == "OBJECT" ? "data" : "srcdoc", "data:text/html," + pageData.content);
+							frameElement.sandbox = true;
 						}
 					}
 				} else {
-					if (frameElement.tagName == "OBJECT") {
-						frameElement.setAttribute("data", "about:blank");
-					} else {
-						frameElement.setAttribute("src", "about:blank");
-					}
+					setFrameEmptySrc(frameElement);
 				}
 			}));
 		}
@@ -538,7 +515,7 @@ const SingleFileCore = (() => {
 						const pageData = await processor.getPageData();
 						linkElement.setAttribute("href", "data:text/html," + pageData.content);
 					} else {
-						linkElement.setAttribute("href", "about:blank");
+						linkElement.setAttribute("href", EMPTY_DATA_URI);
 					}
 				}
 			}));