summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorSamuel Degueldre <sad@odoo.com>2020-10-09 09:05:48 +0000
committerSamuel Degueldre <sad@odoo.com>2020-10-09 11:48:02 +0000
commit5d8c0aa0f7678f51e0a0931b0410a0273c7c7d1f (patch)
tree45b8012f3c14ae172f6540814baeee13e2a746a5 /addons/web_editor/static/src/js
parent118e52b748a9e0faec45be0ddf1a9e4a94a3f37c (diff)
[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#59587 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/editor/image_processing.js2
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js23
2 files changed, 16 insertions, 9 deletions
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 baafd5f9903..7a30b60346e 100644
--- a/addons/web_editor/static/src/js/editor/image_processing.js
+++ b/addons/web_editor/static/src/js/editor/image_processing.js
@@ -201,7 +201,7 @@ async function applyModifications(img) {
const data = Object.assign({
glFilter: '',
filter: '#0000',
- quality: '95',
+ quality: '75',
}, img.dataset);
let {
width,
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 14bc101290f..dc959f91125 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -3174,7 +3174,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 || "{}");
@@ -3269,6 +3269,18 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
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.
*
* @private
@@ -3348,11 +3360,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');
}});
},
@@ -3453,8 +3461,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();
}});
}
},