Skip to content

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

FIX: Show quoted images correctly. (#8391)

Dan Ungureanud5f5d9b8676d
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 12f78fc3f50..b8a4cad87fa 100644
--- a/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
+++ b/app/assets/javascripts/discourse/lib/lazy-load-images.js.es6
@@ -56,10 +56,16 @@ function show(image) {
copyImg.className = imageData.className;
let inOnebox = false;
+ let inQuote = false;
for (let element = image; element; element = element.parentElement) {
+ if (element.tagName === "ARTICLE") {
+ break;
+ }
if (element.classList.contains("onebox")) {
inOnebox = true;
- break;
+ }
+ if (element.tagName === "BLOCKQUOTE") {
+ inQuote = true;
}
}
@@ -68,6 +74,18 @@ function show(image) {
copyImg.style.height = `${imageData.height}px`;
}
+ if (inQuote && imageData.width && imageData.height) {
+ const computedStyle = window.getComputedStyle(image);
+ const width = parseInt(computedStyle.width, 10);
+ const height = width * (imageData.height / imageData.width);
+
+ image.width = width;
+ image.height = height;
+
+ copyImg.style.width = `${width}px`;
+ copyImg.style.height = `${height}px`;
+ }
+
image.parentNode.insertBefore(copyImg, image);
} else {
image.classList.remove("d-lazyload-hidden");
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss
index 42df697e4a0..e1eafd1dc14 100644
--- a/app/assets/stylesheets/common/base/topic-post.scss
+++ b/app/assets/stylesheets/common/base/topic-post.scss
@@ -233,8 +233,6 @@ blockquote {
// !important here otherwise it won't work.
img {
max-width: 100% !important;
- object-fit: cover;
- object-position: top;
}
}