From 6d4900826b14e6b6fb252bc6c539737cf04281a1 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 28 Jul 2017 10:32:00 +0200 Subject: [PATCH] [REF] web, *: improve behavior of jQuery extension 'prependEvent' * web_editor Odoo extends jQuery to add some utility functions. The 'prependEvent' one add the possibility to add an event handler on an element (like the jQuery built-in 'on' function) but to be executed before the already binded ones. This function was however incomplete and did not allow to use jQuery namespaced events. --- addons/web/static/src/js/libs/jquery.js | 3 ++- addons/web_editor/static/src/js/translator.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/libs/jquery.js b/addons/web/static/src/js/libs/jquery.js index 8722025663e..30afa4db274 100644 --- a/addons/web/static/src/js/libs/jquery.js +++ b/addons/web/static/src/js/libs/jquery.js @@ -110,7 +110,8 @@ $.fn.extend({ events = events.split(' '); return this.each(function () { var el = this; - _.each(events, function (evName) { + _.each(events, function (evNameNamespaced) { + var evName = evNameNamespaced.split('.')[0]; var handler = $._data(el, 'events')[evName].pop(); $._data(el, 'events')[evName].unshift(handler); }); diff --git a/addons/web_editor/static/src/js/translator.js b/addons/web_editor/static/src/js/translator.js index 9d1ebe94082..e82ebbb5b81 100644 --- a/addons/web_editor/static/src/js/translator.js +++ b/addons/web_editor/static/src/js/translator.js @@ -207,7 +207,7 @@ var Translate = Widget.extend({ var trans = self.getTranlationObject(this); trans.value = (trans.value ? trans.value : $node.html() ).replace(/[ \t\n\r]+/, ' '); }); - this.$target.parent().prependEvent('click', this, this.__unbind_click); + this.$target.parent().prependEvent('click.translator', this, this.__unbind_click); // attributes @@ -221,14 +221,14 @@ var Translate = Widget.extend({ }); }); - this.$target_attr.prependEvent('mousedown click mouseup', this, this.__translate_attribute); + this.$target_attr.prependEvent('mousedown.translator click.translator mouseup.translator', this, this.__translate_attribute); console.info('Click on CTRL when you click in an translatable area to have the default behavior'); }, unarkTranslatableNode: function () { this.$target.removeClass('o_editable').removeAttr('contentEditable'); - this.$target.parent().off('click', this.__unbind_click); - this.$target_attr.off('mousedown click mouseup', this.__translate_attribute); + this.$target.parent().off('.translator'); + this.$target_attr.off('.translator'); }, save_and_reload: function () { return this.save().then(function () {