diff --git a/addons/web_editor/static/src/js/editor/image_processing.js b/addons/web_editor/static/src/js/editor/image_processing.js index 87d68adb0bd..84fdd77d414 100644 --- a/addons/web_editor/static/src/js/editor/image_processing.js +++ b/addons/web_editor/static/src/js/editor/image_processing.js @@ -456,6 +456,13 @@ function isImageSupportedForProcessing(mimetype, strict = false) { } return ['image/jpeg', 'image/png'].includes(mimetype); } +/** + * @param {HTMLImageElement} img + * @returns {Boolean} + */ +function isImageSupportedForStyle(img) { + return img.parentElement && !img.parentElement.dataset.oeType; +} /** * @param {Blob} blob @@ -479,6 +486,7 @@ return { loadImage, removeOnImageChangeAttrs: [...cropperDataFields, ...modifierFields, 'aspectRatio'], isImageSupportedForProcessing, + isImageSupportedForStyle, createDataURL, isGif, }; diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index eed090765b0..b36ffb1f336 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -25,6 +25,7 @@ const { applyModifications, removeOnImageChangeAttrs, isImageSupportedForProcessing, + isImageSupportedForStyle, createDataURL, isGif, } = require('web_editor.image_processing'); @@ -4912,6 +4913,9 @@ registry.ReplaceMedia = SnippetOptionWidget.extend({ */ async _computeWidgetVisibility(widgetName, params) { if (widgetName === 'media_link_opt') { + if (this.$target[0].matches('img')) { + return isImageSupportedForStyle(this.$target[0]); + } return !this.$target[0].classList.contains('media_iframe_video'); } return this._super(...arguments); @@ -5216,7 +5220,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({ const img = this._getImg(); return this._isImageSupportedForProcessing(img, true); } - return this._super(...arguments); + return isImageSupportedForStyle(this._getImg()); }, /** * Indicates if an option should be applied only on supported mimetypes. @@ -5593,6 +5597,10 @@ registry.ImageTools = ImageHandlerOption.extend({ if (params.optionsPossibleValues.resetCrop) { return this._isCropped(); } + if (params.optionsPossibleValues.crop) { + const img = this._getImg(); + return isImageSupportedForStyle(img) || this._isImageSupportedForProcessing(img); + } return this._super(...arguments); }, /** diff --git a/addons/web_editor/views/snippets.xml b/addons/web_editor/views/snippets.xml index 44764a825d8..aceff75bac2 100644 --- a/addons/web_editor/views/snippets.xml +++ b/addons/web_editor/views/snippets.xml @@ -428,7 +428,7 @@ -