[FIX] web_editor: fix background-images not being auto-optimized on drop
Previously, background-images were not properly optimized when inserted, whereas they should be just like regular images. This commit fixes that. It also changes the default quality (used for automatic optimization) to 75 as the difference is not usually very noticeable but can bring a big decrease in image size. task-2357332 closes odoo/odoo#59779 X-original-commit: 5d8c0aa0f7678f51e0a0931b0410a0273c7c7d1f Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -201,7 +201,7 @@ async function applyModifications(img) {
|
||||
const data = Object.assign({
|
||||
glFilter: '',
|
||||
filter: '#0000',
|
||||
quality: '95',
|
||||
quality: '75',
|
||||
}, img.dataset);
|
||||
let {
|
||||
width,
|
||||
|
||||
@@ -3184,7 +3184,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
|
||||
case 'glFilter':
|
||||
return img.dataset.glFilter || "";
|
||||
case 'setQuality':
|
||||
return img.dataset.quality || 95;
|
||||
return img.dataset.quality || 75;
|
||||
case 'customFilter': {
|
||||
const {filterProperty} = params;
|
||||
const options = JSON.parse(img.dataset.filterOptions || "{}");
|
||||
@@ -3278,6 +3278,18 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
|
||||
this.originalId = img.dataset.originalId;
|
||||
this.originalSrc = img.dataset.originalSrc;
|
||||
},
|
||||
/**
|
||||
* Sets the image's width to its suggested size.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
async _autoOptimizeImage() {
|
||||
await this._loadImageInfo();
|
||||
await this._rerenderXML();
|
||||
this._getImg().dataset.resizeWidth = this.optimizedWidth;
|
||||
await this._applyOptions();
|
||||
await this.updateUI();
|
||||
},
|
||||
/**
|
||||
* Returns the image that is currently being modified.
|
||||
*
|
||||
@@ -3358,11 +3370,7 @@ registry.ImageOptimize = ImageHandlerOption.extend({
|
||||
*/
|
||||
async _onImageChanged(ev) {
|
||||
this.trigger_up('snippet_edition_request', {exec: async () => {
|
||||
await this._loadImageInfo();
|
||||
await this._rerenderXML();
|
||||
this._getImg().dataset.resizeWidth = this.optimizedWidth;
|
||||
await this._applyOptions();
|
||||
await this.updateUI();
|
||||
await this._autoOptimizeImage();
|
||||
this.trigger_up('cover_update');
|
||||
}});
|
||||
},
|
||||
@@ -3463,8 +3471,7 @@ registry.BackgroundOptimize = ImageHandlerOption.extend({
|
||||
async _onBackgroundChanged(ev, previewMode) {
|
||||
if (!previewMode) {
|
||||
this.trigger_up('snippet_edition_request', {exec: async () => {
|
||||
await this._loadImageInfo();
|
||||
await this._rerenderXML();
|
||||
await this._autoOptimizeImage();
|
||||
}});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user