[FIX] web_editor: modify background element at option change
For background images, modifying options such as "Filter" does not directly lead to the modification of their corresponding data attributes in the DOM as those modifications are done at the save request. This should not be the case. The goal of this commit is to, as for regular images, modify their corresponding DOM data attributes at the option update. Steps to reproduce the bug: - Add a Cover snippet on the website. - Replace the background image by one of your own. - Add a filter to the background image. - Inspect the Cover snippet. => The `data-gl-filter` attribute has not been added in the DOM and you have to click on "Save" for it to be actually added. task-3287330 X-original-commit: ed19a1e91a2706b157532778b15d4a581a4da0e2 Part-of: odoo/odoo#123873
This commit is contained in:
@@ -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");
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user