Procházet zdrojové kódy

avoid overriding existing background images

Gildas před 7 roky
rodič
revize
4a148b286c

+ 3 - 2
lib/single-file/doc-helper.js

@@ -165,9 +165,10 @@ this.docHelper = this.docHelper || (() => {
 		if (doc) {
 			const data = [];
 			doc.querySelectorAll("img[src]").forEach((imageElement, imageElementIndex) => {
-				imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
+				const computedStyle = getComputedStyle(imageElement);
 				let imageData = {}, size = getSize(imageElement);
-				if (imageElement.src && size) {
+				if (imageElement.src && size && !computedStyle.getPropertyValue("background-image")) {
+					imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
 					imageData = size;
 				}
 				data.push(imageData);

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

@@ -1080,10 +1080,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 							} else {
 								if (content.startsWith(prefixDataURI) || content.startsWith(PREFIX_DATA_URI_NO_MIMETYPE) || content.startsWith(PREFIX_DATA_URI_OCTET_STREAM)) {
 									if (processDuplicates && duplicate && options.groupDuplicateImages) {
-										if (resourceElement.style.getPropertyValue("background-image")) {
-											resourceElement.setAttribute(attributeName, content);
-										} else {
-											DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options);
+										if (DomUtil.replaceImageSource(resourceElement, SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource, options)) {
 											DomUtil.insertVariable(doc, indexResource, content, options);
 										}
 									} else {
@@ -1305,6 +1302,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				imgElement.style.setProperty("background-origin", "content-box", "important");
 				imgElement.style.setProperty("background-repeat", "no-repeat", "important");
 				imgElement.removeAttribute(dataAttributeName);
+				return true;
 			}
 		}