From abac61449282cce61886fb1b50a3587a579e6406 Mon Sep 17 00:00:00 2001 From: jbrw Date: Wed, 2 Jun 2021 20:02:13 -0400 Subject: [PATCH] FIX: Ignore `allowlistgeneric` Onebox image sizes (#13240) * FIX: Ignore `allowlistgeneric` Onebox image sizes The size of an image contained within the preview pane of a Composer window may vary depending on the configuration of the browser displaying the Composer (e.g., dimension of browser window, zoom level, etc.). Presently, the dimensions of the images from the browser creating the post containing the Onebox will be used to render the Onebox to anyone who views the post. It is safer to let the backend figure out the dimensions of the images. Therefore, exclude `.onebox.allowlistedgeneric` images from the list of `image_sizes` sent to the backend. * DEV: Replace jQuery selector with pure JS * DEV: remove more jQuery --- .../discourse/app/controllers/composer.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index e0c09b70b51..f23101835e8 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -770,14 +770,15 @@ export default Controller.extend({ // TODO: This should not happen in model const imageSizes = {}; - $("#reply-control .d-editor-preview img").each((i, e) => { - const $img = $(e); - const src = $img.prop("src"); + document + .querySelectorAll("#reply-control .d-editor-preview img:not(.onebox img)") + .forEach((e) => { + const src = e.src; - if (src && src.length) { - imageSizes[src] = { width: $img.width(), height: $img.height() }; - } - }); + if (src && src.length) { + imageSizes[src] = { width: e.width, height: e.height }; + } + }); const promise = composer .save({ imageSizes, editReason: this.editReason })