From 35da531f1d2ae5f4f8eadcd38bd19e2a1ecf3a10 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Thu, 6 Jun 2019 18:36:18 +0300 Subject: [PATCH] FIX: Do not resize images in Onebox while lazy loading. Follow-up to 35d0fd0. --- .../discourse/lib/lazy-load-images.js.es6 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 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 c6d70df3ab..035ccf572f 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");