From 9f183ea0e90546a25858bb15e2cd00faac6df3e8 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 4 Aug 2023 11:07:07 +0000 Subject: [PATCH] [FIX] web_editor: properly bind dblclick to videos to edit them Commit [1] refactored the event handler code in charge of handling double click on media elements to edit them. A mistake was made making the code consider inner elements of the media instead of the media as a whole when clicking on it. Steps to reproduce: - Enter edit mode on the homepage - Add a text-image snippet - Change the image to a video (after dblclick on the image for instance) - Try to change it back with a dblclick => it does nothing [1]: https://github.com/odoo/odoo/commit/8ca115b3b9dfe87b59b6b064a4d85ea152d9214c X-original-commit: 4b47ae0022a3e50d53dc02e399412585fc2131ef Part-of: odoo/odoo#131139 --- addons/web_editor/static/src/js/backend/html_field.js | 2 +- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 596c919be73..3f85f77dca2 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -546,7 +546,7 @@ export class HtmlField extends Component { this.props.record.data.attachment_ids.linkTo(attachment.res_id, attachment); } _onDblClickEditableMedia(ev) { - const el = ev.target; + const el = ev.currentTarget; if (el.nodeName === 'IMG' && el.src) { this.wysiwyg.showImageFullscreen(el.src); } diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 58ee68d88b8..317e2cf98d3 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -486,12 +486,12 @@ export class Wysiwyg extends Component { this.$editable.on('click', '.o_image, .media_iframe_video', e => e.preventDefault()); this.showTooltip = true; this.$editable.on('dblclick', mediaSelector, ev => { - const target = ev.target; - if (target.isContentEditable || (target.parentElement && target.parentElement.isContentEditable)) { + const targetEl = ev.currentTarget; + if (targetEl.isContentEditable || (targetEl.parentElement && targetEl.parentElement.isContentEditable)) { this.showTooltip = false; if (!isProtected(this.odooEditor.document.getSelection().anchorNode)) { - if (this.options.onDblClickEditableMedia && target.nodeName === 'IMG' && target.src) { + if (this.options.onDblClickEditableMedia && targetEl.nodeName === 'IMG' && targetEl.src) { this.options.onDblClickEditableMedia(ev); } else { this._onDblClickEditableMedia(ev); @@ -2692,7 +2692,7 @@ export class Wysiwyg extends Component { } } _onDblClickEditableMedia(ev) { - const $el = $(ev.target); + const $el = $(ev.currentTarget); $el.selectElement(); if (!$el.parent().hasClass('o_stars')) { // Waiting for all the options to be initialized before @@ -2700,7 +2700,7 @@ export class Wysiwyg extends Component { // been deleted in the meantime. this.waitForEmptyMutexAction().then(() => { if ($el[0].parentElement) { - this.openMediaDialog({ node: ev.target }); + this.openMediaDialog({ node: $el[0] }); } }); }