Kaynağa Gözat

save input values found in the shadow dom

Former-commit-id: 10876b575327b64e463461f09e47aaffaad05900
Gildas 6 yıl önce
ebeveyn
işleme
ae840dab6c
1 değiştirilmiş dosya ile 18 ekleme ve 14 silme
  1. 18 14
      lib/single-file/single-file-helper.js

+ 18 - 14
lib/single-file/single-file-helper.js

@@ -95,7 +95,6 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 				imports: []
 			};
 		}
-		saveInputValues(doc);
 		return {
 			canvases: elementsInfo.canvases,
 			fonts: getFontsData(doc),
@@ -216,6 +215,24 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 				element.setAttribute(HTML_IMPORT_ATTRIBUTE_NAME, data.imports.length - 1);
 			}
 		}
+		if (element.tagName == "INPUT") {
+			if (element.type != "password") {
+				element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.value);
+			}
+			if (element.type == "radio" || element.type == "checkbox") {
+				element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.checked);
+			}
+		}
+		if (element.tagName == "TEXTAREA") {
+			element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.value);
+		}
+		if (element.tagName == "SELECT") {
+			element.querySelectorAll("option").forEach(option => {
+				if (option.selected) {
+					option.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, "");
+				}
+			});
+		}
 	}
 
 	function getUsedFont(computedStyle, options, usedFonts) {
@@ -350,19 +367,6 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		}
 	}
 
-	function saveInputValues(doc) {
-		doc.querySelectorAll("input:not([type=password])").forEach(input => input.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, input.value));
-		doc.querySelectorAll("input[type=radio], input[type=checkbox]").forEach(input => input.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, input.checked));
-		doc.querySelectorAll("textarea").forEach(textarea => textarea.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, textarea.value));
-		doc.querySelectorAll("select").forEach(select => {
-			select.querySelectorAll("option").forEach(option => {
-				if (option.selected) {
-					option.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, "");
-				}
-			});
-		});
-	}
-
 	function serialize(doc) {
 		const docType = doc.doctype;
 		let docTypeString = "";