From ea65573b48b35e5d99bc31410941c8363b37614e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Nov 2013 10:20:18 +0100 Subject: [PATCH] [ADD] image edition button v0 bzr revid: xmo@openerp.com-20131107092018-66tae9nu1kcft21g --- .../website/static/src/js/website.editor.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index b23ccf7a9f0..9f5e32ae183 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -63,6 +63,39 @@ link_dialog(editor); }, null, null, 500); + var previousSelection; + editor.on('selectionChange', function (evt) { + var selected = evt.data.path.lastElement; + if (previousSelection) { + // cleanup previous selection + $(previousSelection).next().remove(); + previousSelection = null; + } + if (!selected.is('img') + || selected.data('cke-realelement') + || selected.isReadOnly() + || selected.data('oe-model') === 'ir.ui.view') { + return; + } + + // display button + var $el = $(previousSelection = selected.$); + var $btn = $('') + .insertAfter($el) + .click(function (e) { + e.preventDefault(); + e.stopPropagation(); + image_dialog(editor); + }); + + var position = $el.position(); + $btn.css({ + position: 'absolute', + top: $el.height() / 2 + position.top - $btn.outerHeight() / 2, + left: $el.width() / 2 + position.left - $btn.outerWidth() / 2, + }); + }); + //noinspection JSValidateTypes editor.addCommand('link', { exec: function (editor) {