FIX: Do not resize images in Onebox while lazy loading.

FIX: Do not resize images in Onebox while lazy loading.

Follow-up to 35d0fd0.

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 c6d70df..035ccf5 100644
--- a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
+++ b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
@@ -53,10 +53,21 @@ function show(image) {
     copyImg.style.position = "absolute";
     copyImg.style.top = `${image.offsetTop}px`;
     copyImg.style.left = `${image.offsetLeft}px`;
-    copyImg.style.width = `${imageData.width}px`;
-    copyImg.style.height = `${imageData.height}px`;
     copyImg.className = imageData.className;
 
+    let inOnebox = false;
+    for (let element = image; element; element = element.parentElement) {
+      if (element.classList.contains("onebox")) {
+        inOnebox = true;
+        break;
+      }
+    }
+
+    if (!inOnebox) {
+      copyImg.style.width = `${imageData.width}px`;
+      copyImg.style.height = `${imageData.height}px`;
+    }
+
     image.parentNode.insertBefore(copyImg, image);
   } else {
     image.classList.remove("d-lazyload-hidden");

GitHub sha: 35da531f

2 Likes