From e474bd5f4b47f65483c143cbe95747f31b554e81 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Mon, 22 Jan 2024 12:14:31 +0100 Subject: [PATCH] [FIX] web_editor: factorize open Cropper from toolbar Before this commit, the cropper tool was opened by a closure that spawned the Cropper tool aside from the editable document. This was anoying as the editable document can be in an iframe, hence the Cropper would have been virtually unusable. This commit factorizes the code in a method to allow overrides. Which is done in web_studio:ReportEditorWysiwyg. opw-3484065 closes odoo/odoo#150904 Related: odoo/enterprise#55049 Signed-off-by: Lucas Perais (lpe) --- .../static/src/js/wysiwyg/wysiwyg.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 4edb4677ada..eb391dd1417 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1895,15 +1895,7 @@ export class Wysiwyg extends Component { } this._updateMediaJustifyButton(justifyBtn.id); }); - $toolbar.find('#image-crop').click(e => { - if (!this.lastMediaClicked) { - return; - } - this.imageCropProps.media = this.lastMediaClicked; - this.imageCropProps.showCount++; - this.odooEditor.toolbarHide(); - $(this.lastMediaClicked).on('image_cropper_destroyed', () => this.odooEditor.toolbarShow()); - }); + $toolbar.find('#image-crop').click(() => this._showImageCrop()); $toolbar.find('#image-transform').click(e => { if (!this.lastMediaClicked) { return; @@ -1955,6 +1947,16 @@ export class Wysiwyg extends Component { document.addEventListener('scroll', this._onScroll, true); } } + + _showImageCrop() { + if (!this.lastMediaClicked) { + return; + } + this.imageCropProps.media = this.lastMediaClicked; + this.imageCropProps.showCount++; + this.odooEditor.toolbarHide(); + $(this.lastMediaClicked).on('image_cropper_destroyed', () => this.odooEditor.toolbarShow()); + } /** * @private * @param {jQuery} $