set only atributes existing on the original image

This commit is contained in:
Jonas Leder 2022-07-15 15:43:58 +02:00
parent 7e56c51ca9
commit b1db76d7c5
1 changed files with 8 additions and 8 deletions

View File

@ -21,13 +21,13 @@ class CustomImage extends HTMLElement {
let image = document.createElement("img");
image.src = imgproxy;
image.setAttribute("alt", this.getAttribute("alt"));
image.setAttribute("title", this.getAttribute("title"));
image.setAttribute("class", this.getAttribute("class"));
image.setAttribute("style", this.getAttribute("style"));
image.setAttribute("width", this.getAttribute("width"));
image.setAttribute("height", this.getAttribute("height"));
image.setAttribute("id", this.getAttribute("id"));
if(this.getAttribute("alt") != null) image.setAttribute("alt", this.getAttribute("alt"));
if(this.getAttribute("title") != null) image.setAttribute("title", this.getAttribute("title"));
if(this.getAttribute("class") != null) image.setAttribute("class", this.getAttribute("class"));
if(this.getAttribute("style") != null) image.setAttribute("style", this.getAttribute("style"));
if(this.getAttribute("width") != null) image.setAttribute("width", this.getAttribute("width"));
if(this.getAttribute("height") != null) image.setAttribute("height", this.getAttribute("height"));
if(this.getAttribute("id") != null) image.setAttribute("id", this.getAttribute("id"));
image.setAttribute("loading", "lazy");
image.setAttribute("original-src", originalURL);
this.appendChild(image);
@ -45,4 +45,4 @@ class CustomImage extends HTMLElement {
}
}
customElements.define("jl-img", CustomImage)
customElements.define("jl-img", CustomImage)