Skip to content

A platform for community discussion. Free, open, simple.

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

Bianca Nenciu35da531f1d2a
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 c6d70df3ab6..035ccf572f3 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");