Răsfoiți Sursa

moved WIN_ID_ATTRIBUTE_NAME into common.js

Gildas 7 ani în urmă
părinte
comite
fc9e600851

+ 4 - 1
lib/single-file/doc-helper.js

@@ -22,13 +22,15 @@ this.docHelper = this.docHelper || (() => {
 
 	const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
 	const PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME = "data-single-file-preserved-space-element";
+	const WIN_ID_ATTRIBUTE_NAME = "data-frame-tree-win-id";
 
 	return {
 		preProcessDoc,
 		postProcessDoc,
 		getCanvasData,
 		getEmptyStyleRulesText,
-		getDoctype
+		getDoctype,
+		WIN_ID_ATTRIBUTE_NAME
 	};
 
 	function preProcessDoc(doc, win, options) {
@@ -71,6 +73,7 @@ this.docHelper = this.docHelper || (() => {
 		if (options.compressHTML) {
 			doc.querySelectorAll("[" + PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME));
 		}
+		doc.querySelectorAll("[" + WIN_ID_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(WIN_ID_ATTRIBUTE_NAME));
 	}
 
 	function getCanvasData(doc) {

+ 1 - 1
lib/single-file/frame-tree/content/frame-tree.js

@@ -170,7 +170,7 @@ this.FrameTree = this.FrameTree || (() => {
 		top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId, index }), "*");
 		frameElements.forEach((frameElement, index) => {
 			const frameWinId = windowId + "." + index;
-			frameElement.setAttribute("data-frame-tree-win-id", frameWinId);
+			frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, frameWinId);
 			let frameDoc, frameWindow, topWindow;
 			try {
 				frameDoc = frameElement.contentDocument;

+ 3 - 0
lib/single-file/single-file-browser.js

@@ -149,6 +149,9 @@ this.SingleFile = this.SingleFile || (() => {
 		static getCanvasData(doc) {
 			return docHelper.getCanvasData(doc);
 		}
+		static winIdAttributeName() {
+			return docHelper.WIN_ID_ATTRIBUTE_NAME;
+		}
 	}
 
 	return { getClass: () => SingleFileCore.getClass(Download, DOM, URL) };

+ 2 - 10
lib/single-file/single-file-core.js

@@ -26,7 +26,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 	const SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = "data-single-file-selected-content-root";
 	const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
 	const PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME = "data-single-file-preserved-space-element";
-	const WIN_ID_ATTRIBUTE_NAME = "data-frame-tree-win-id";
 
 	let Download, DOM, URL;
 
@@ -141,9 +140,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 			if (this.options.doc) {
 				DOM.postProcessDoc(this.options.doc, this.options);
-				if (!this.options.removeFrames) {
-					this.processor.removeWindowIdFrames();
-				}
 				this.options.doc = null;
 				this.options.win = null;
 			}
@@ -320,10 +316,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			};
 		}
 
-		removeWindowIdFrames() {
-			this.options.doc.querySelectorAll("[" + WIN_ID_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(WIN_ID_ATTRIBUTE_NAME));
-		}
-
 		enableDisabledNoscriptTags(noscriptTags) {
 			noscriptTags.forEach(element => {
 				const noscriptElement = this.options.doc.createElement("noscript");
@@ -573,7 +565,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			await Promise.all(frameElements.map(async frameElement => {
 				DomProcessorHelper.setFrameEmptySrc(frameElement);
 				frameElement.setAttribute("sandbox", "");
-				const frameWindowId = frameElement.getAttribute(WIN_ID_ATTRIBUTE_NAME);
+				const frameWindowId = frameElement.getAttribute(DOM.winIdAttributeName());
 				if (frameWindowId) {
 					const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
 					if (frameData) {
@@ -599,7 +591,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 								}
 								await frameData.processor.preparePageData();
 								const pageData = await frameData.processor.getPageData();
-								frameElement.removeAttribute(WIN_ID_ATTRIBUTE_NAME);
+								frameElement.removeAttribute(DOM.winIdAttributeName());
 								DomProcessorHelper.setFrameContent(frameElement, pageData.content);
 								if (this.options.displayStats) {
 									Object.keys(this.stats.discarded).forEach(key => this.stats.discarded[key] += (pageData.stats.discarded[key] || 0));