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 b9b64579361..202f6385546 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -6539,22 +6539,6 @@ registry.BackgroundOptimize = ImageHandlerOption.extend({ this.$target.off('.BackgroundOptimize'); return this._super(...arguments); }, - /** - * Marks the target for creation of an attachment and copies data attributes - * to the target so that they can be restored on this.img in later editions. - * - * @override - */ - async cleanForSave() { - const img = this._getImg(); - if (img.matches('.o_modified_image_to_save')) { - this.$target.addClass('o_modified_image_to_save'); - Object.entries(img.dataset).forEach(([key, value]) => { - this.$target[0].dataset[key] = value; - }); - this.$target[0].dataset.bgSrc = img.getAttribute('src'); - } - }, //-------------------------------------------------------------------------- // Private @@ -6611,6 +6595,21 @@ registry.BackgroundOptimize = ImageHandlerOption.extend({ parts.url = `url('${img.getAttribute('src')}')`; const combined = backgroundImagePartsToCss(parts); this.$target.css('background-image', combined); + // Apply modification on the DOM HTML element that is currently being + // modified. + this.$target[0].classList.add("o_modified_image_to_save"); + // First delete the data attributes relative to the image background + // from the target as a data attribute could have been be removed (ex: + // glFilter). + for (const attribute in this.$target[0].dataset) { + if (isBackgroundImageAttribute(attribute)) { + delete this.$target[0].dataset[attribute]; + } + } + Object.entries(img.dataset).forEach(([key, value]) => { + this.$target[0].dataset[key] = value; + }); + this.$target[0].dataset.bgSrc = img.getAttribute("src"); }, //--------------------------------------------------------------------------