From 2f97feb322221dc047004af0b9f28bb592b760f3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 2 Sep 2013 12:54:11 +0200 Subject: [PATCH] [ADD] interaction between RTE and bootstrap image modal bzr revid: xmo@openerp.com-20130902105411-ni3klun0k8v1tmjg --- .../website/static/src/js/website.editor.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 5562bf2ca66..ee14b113e8e 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -471,6 +471,34 @@ }, 'change input[type=file]': 'file_selection', }), + start: function () { + var selection = this.editor.getSelection(); + var el = selection && selection.getSelectedElement(); + this.element = null; + if (el && el.is('img')) { + this.element = el; + this.$('input.url').val(el.getAttribute('src')); + } + + return this._super(); + }, + save: function () { + var url = this.$('input.url').val(); + var element, editor = this.editor; + if (!(element = this.element)) { + element = editor.document.createElement('img'); + // focus event handler interactions between bootstrap (modal) + // and ckeditor (RTE) lead to blowing the stack in Safari and + // Chrome (but not FF) when this is done synchronously => + // defer insertion so modal has been hidden & destroyed before + // it happens + setTimeout(function () { + editor.insertElement(element); + }, 0); + } + element.setAttribute('src', url); + this._super(); + }, file_selection: function (e) { this.$('button.filepicker').removeClass('btn-danger btn-success');