Skip to content

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

FIX: use full image for lightbox zoom when thumbnail aspect ratio differs (#37284)

small-lovely-cat99525c75868e
diff --git a/frontend/discourse/app/lib/lightbox.js b/frontend/discourse/app/lib/lightbox.js
index e40893a3d31..9c6fe0727b1 100644
--- a/frontend/discourse/app/lib/lightbox.js
+++ b/frontend/discourse/app/lib/lightbox.js
@@ -292,6 +292,16 @@ export default async function lightbox(elem, additionalData = {}) {
imgEl?.getAttribute("height") ||
null;
+ // If thumbnail has different aspect ratio than full image,
+ // use the full image as msrc for smooth zoom animation
+ if (data.targetWidth && data.targetHeight && data.w && data.h) {
+ const thumbRatio = data.targetWidth / data.targetHeight;
+ const fullRatio = data.w / data.h;
+ if (Math.abs(thumbRatio - fullRatio) / fullRatio > 0.05) {
+ data.msrc = data.src;
+ }
+ }
+
// So we can attach things like a Post model from the caller.
Object.keys(additionalData).forEach((key) => {
data[key] = additionalData[key];