[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.
This commit is contained in:
qsm-odoo
2017-08-03 10:50:55 +02:00
parent 847afa1b69
commit 6d4900826b
2 changed files with 6 additions and 5 deletions
+2 -1
View File
@@ -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);
});
@@ -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 () {