From 57c00ebea50263b79fd67953f08df3e616c2869d Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 18 Aug 2015 08:43:09 +0200 Subject: [PATCH] [FIX] website: escape when in a modal don't close editor When a bootstrap modal is closed via the escape key, the editor would snatch this keydown event and think we want to stop the editing. --- addons/website/static/src/js/website.editor.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index b2603a79c16..7447cd822c1 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1131,6 +1131,8 @@ define(['summernote/summernote'], function () { d.resolve(); }).on('hidden.bs.modal', function () { d.reject(); + }).on('keydown.dismiss.bs.modal', function (event) { + event.stopImmediatePropagation(); }); d.always(function () { $dialog.remove(); @@ -1393,6 +1395,7 @@ define(['summernote/summernote'], function () { website.editor.Dialog = openerp.Widget.extend({ events: { 'hidden.bs.modal': 'destroy', + 'keydown.dismiss.bs.modal': 'stop_escape', 'click button.save': 'save', 'click button[data-dismiss="modal"]': 'cancel', }, @@ -1421,6 +1424,11 @@ define(['summernote/summernote'], function () { $('body').addClass('modal-open'); } }, + stop_escape: function(event) { + if($(".modal.in").length>0 && event.which == 27){ + event.stopPropagation(); + } + } }); website.editor.LinkDialog = website.editor.Dialog.extend({ @@ -1914,6 +1922,7 @@ define(['summernote/summernote'], function () { //'change select.image-style': 'preview_image', 'click .existing-attachments img': 'select_existing', 'click .existing-attachment-remove': 'try_remove', + 'keydown.dismiss.bs.modal': function(){}, }), init: function (parent, media, options) { this._super(); @@ -2244,6 +2253,7 @@ define(['summernote/summernote'], function () { $(".font-icons-icon").removeClass("font-icons-selected"); $(event.target).addClass("font-icons-selected"); }, + 'keydown.dismiss.bs.modal': function(){}, }), // extract list of font (like awsome) from the cheatsheet. @@ -2462,7 +2472,8 @@ define(['summernote/summernote'], function () { 'change input#urlvideo': 'change_input', 'keyup input#urlvideo': 'change_input', 'change input#embedvideo': 'change_input', - 'keyup input#embedvideo': 'change_input' + 'keyup input#embedvideo': 'change_input', + 'keydown.dismiss.bs.modal': function(){}, }), init: function (parent, media) { this._super();