[FIX] web_editor: fix select and modify video

There was an issue when selecting a video tag:

- a tag inside the video tag would be selected instead of the video tag
  so video could not be removed or modified (modifying it would add a
  video or image inside the video itself and so on).

- the selection was not conveyed to the editor so it would be lost
  consequently due to some code who restored it to what was saved on
  the editor.

This fix solves this by changing how the video tag was selected and
saving the selected range on the editor.

opw-724701
This commit is contained in:
Nicolas Lempereur
2017-03-29 16:35:39 +02:00
parent 1b5dcf29f5
commit 105243afa6
@@ -267,7 +267,15 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) {
$imagePopover.find('.o_image_alt').text( (alt || "").replace(/"/g, '"') ).parent().toggle(oStyle.image.tagName === "IMG");
$imagePopover.show();
range.createFromNode(dom.firstChild(oStyle.image)).select();
// for video tag (non-void) we select the range over the tag,
// for other media types we get the first descendant leaf element
var target_node = oStyle.image;
if (!oStyle.image.className.match(/(^|\s)media_iframe_video(\s|$)/i)) {
target_node = dom.firstChild(target_node);
}
range.createFromNode(target_node).select();
// save range on the editor so it is not lost if restored
eventHandler.modules.editor.saveRange(dom.makeLayoutInfo(target_node).editable());
} else {
$(".note-control-selection").hide();
}