From bd00fa8dd1808478e70232dfcbd2f4b48f9e1cc8 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 11 Jan 2018 14:10:27 +0100 Subject: [PATCH] [FIX] web_editor: dbclick a video open MediaDialog with wrong media Before this commit: In the web editor, if you double clicked on a video iframe to edit it, it would open the MediaDialog(media) with the wrong media element. Media would be ' ' instead of '.media_iframe_video' (which is its grand parent): div.media_iframe_video div.css_editable_mode_display '& nbsp;' Then, if you changed the media by another one (Image or Video), the media would be wrongly inserted into the DOM, in the already existing iframe, eg: (1) div.media_iframe_video (2) div.css_editable_mode_display (3) div.media_iframe_video (4) div.css_editable_mode_display (5) '  ' Since the new media (3) is wrongly instered into (2) instead of replacing (1), the bug it would not be visible on normal mode (you would still see the old media) because (2) is not displayed on normal mode. Then on edit mode you would see both media one over the other. Note: This only happened when you opened MediaDialog thought double click directly (not 'Edit 'in navbar) and without clicking somewhere else after you entered edit mode. Now, if the media has an iframe parent, we use that parent as the correct media This closes #22109, closes #22179 Courtesy of QSM for the help --- addons/web_editor/static/src/js/rte.summernote.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 866d0d68e84..5f28c9510bb 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -398,7 +398,9 @@ eventHandler.modules.imageDialog.showImageDialog = function ($editable) { if (r.sc.tagName && r.sc.childNodes.length) { r.sc = r.sc.childNodes[r.so]; } - new widgets.MediaDialog(null, {}, $editable, dom.isImg(r.sc) ? r.sc : null).open(); + new widgets.MediaDialog(null, {}, $editable, $(r.sc).parents().addBack().filter(function (i, el) { + return dom.isImg(el); + })[0]).open(); return new $.Deferred().reject(); }; $.summernote.pluginEvents.alt = function (event, editor, layoutInfo, sorted) {