From a2ae67509d8a11ebada6129ea7db9eddaf5bf666 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 20 Dec 2018 16:41:04 -0500 Subject: [PATCH] Don't use `getAttribute` if we don't need to --- .../discourse/lib/lazy-load-images.js.es6 | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6 b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6 index 0700c4928c..e390a9dcf8 100644 --- a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6 +++ b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6 @@ -12,17 +12,11 @@ function hide(image) { image.classList.add("d-lazyload"); image.classList.add("d-lazyload-hidden"); - imageSources.set(image, { - src: image.getAttribute("src"), - srcSet: image.getAttribute("srcset") - }); + imageSources.set(image, { src: image.src, srcset: image.srcset }); image.removeAttribute("srcset"); - image.setAttribute( - "src", - image.getAttribute("data-small-upload") || LOADING_DATA - ); - image.removeAttribute("data-small-upload"); + image.src = image.dataset.smallUpload || LOADING_DATA; + delete image.dataset.smallUpload; } // Restore an image when onscreen @@ -42,9 +36,7 @@ function show(image) { }; copyImg.src = sources.src; - if (sources.srcSet) { - copyImg.srcset = sources.srcSet; - } + copyImg.srcset = sources.srcset || copyImg.srcset; copyImg.style.position = "absolute"; copyImg.style.top = 0;