From 30ec9ffa2d515abd5fa46efe5394261cb72dbd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Souk=C3=A9ina=20Bojabza?= Date: Thu, 4 Jan 2024 14:39:08 +0000 Subject: [PATCH] [FIX] web_editor, website: improve grid image code Commit [1] added the support for images with a link set on them in grid mode. As a follow up, this commit does the following: - Removes the `!important` from the grid image anchor CSS rules, as they were not really needed. - Checks if the image has a closest `o_grid_item_image` column instead of checking the parent in the `GridImage` options. Indeed, this class already guarantees that the image is well a grid image; we can therefore simplify the code. It also removes a comment that was forgotten in commit [2]. [1]: https://github.com/odoo/odoo/commit/085d70cea571ea80c141ac6005e8bd8333bd269f [2]: https://github.com/odoo/odoo/commit/d8c374e3e6b31bf88aa42952aadf3379936f7600 related to opw-3580128 closes odoo/odoo#149681 X-original-commit: 9244e85ebb9e1605292698fe31ad94da7709ab86 Signed-off-by: Quentin Smetz (qsm) --- .../static/src/js/common/grid_layout_utils.js | 3 +-- .../static/src/scss/web_editor.frontend.scss | 4 ++-- .../website/static/src/js/editor/snippets.options.js | 10 +--------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/addons/web_editor/static/src/js/common/grid_layout_utils.js b/addons/web_editor/static/src/js/common/grid_layout_utils.js index ffa5da88b69..317895caaa1 100644 --- a/addons/web_editor/static/src/js/common/grid_layout_utils.js +++ b/addons/web_editor/static/src/js/common/grid_layout_utils.js @@ -326,8 +326,7 @@ export function _checkIfImageColumn(columnEl) { } /** * Removes the line breaks and textnodes of the column, adds the grid class and - * sets the image width to default so it can be displayed as expected. Also - * blocks the edition of the column. + * sets the image width to default so it can be displayed as expected. * * @private * @param {Element} columnEl a column containing only an image. diff --git a/addons/web_editor/static/src/scss/web_editor.frontend.scss b/addons/web_editor/static/src/scss/web_editor.frontend.scss index e2acea2f452..e8be112c676 100644 --- a/addons/web_editor/static/src/scss/web_editor.frontend.scss +++ b/addons/web_editor/static/src/scss/web_editor.frontend.scss @@ -99,8 +99,8 @@ // Needed when "a" is "display: block". > a { - width: 100% !important; - height: 100% !important; + width: 100%; + height: 100%; } } } diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 82f7df86978..fb7525e1154 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -4029,15 +4029,7 @@ options.registry.GridImage = options.Class.extend({ * @returns {?HTMLElement} */ _getImageGridItem() { - let parentEl = this.$target[0].parentNode; - if (parentEl.matches("a")) { - // Case of an image link. - parentEl = parentEl.parentNode; - } - if (parentEl && parentEl.classList.contains('o_grid_item_image')) { - return parentEl; - } - return null; + return this.$target[0].closest(".o_grid_item_image"); }, /** * @override