[FIX] web_editor: use _.bind for rte handler to use 'this' and avoid errors

This commit is contained in:
Christophe Matthieu
2015-11-04 16:10:44 +01:00
parent c7ff7cb491
commit f3ade95862
+21 -19
View File
@@ -296,9 +296,12 @@ var RTE = Widget.extend({
$.fn.carousel = this.edit_bootstrap_carousel;
$(document).on('keydown', this, this.onKeydown);
$(document).on('mousedown activate', this, this.onMousedown);
$(document).on('mouseup', this, this.onMouseup);
this._onKeydown = _.bind(this.onKeydown, this);
$(document).on('keydown', this, this._onKeydown);
this._onMousedown = _.bind(this.onMousedown, this);
$(document).on('mousedown activate', this, this._onMousedown);
this._onMouseup = _.bind(this.onMouseup, this);
$(document).on('mouseup', this, this._onMouseup);
$('.o_not_editable').attr("contentEditable", false);
@@ -325,7 +328,8 @@ var RTE = Widget.extend({
}
});
$('#wrapwrap, .o_editable').on('click', '*', this, this.onClick);
this._onClick = _.bind(this.onClick, this);
$('#wrapwrap, .o_editable').on('click', '*', this, this._onClick);
$('body').addClass("editor_enable");
@@ -460,12 +464,12 @@ var RTE = Widget.extend({
$.fn.carousel = this.init_bootstrap_carousel;
$(document).off('keydown', this.onKeydown);
$(document).off('mousedown applySnap', this.onMousedown);
$(document).off('mouseup', this.onMouseup);
$(document).off('keydown', this._onKeydown);
$(document).off('mousedown applySnap', this._onMousedown);
$(document).off('mouseup', this._onMouseup);
$('.o_not_editable').removeAttr("contentEditable");
$(document).off('content_changed').removeClass('o_is_inline_editable').removeData('rte');
$('#wrapwrap, .o_editable').off('click', this.onClick);
$('#wrapwrap, .o_editable').off('click', this._onClick);
$(document).tooltip('destroy');
$('body').removeClass("editor_enable");
this.trigger('rte:stop');
@@ -508,10 +512,8 @@ var RTE = Widget.extend({
return;
}
var rte = $editable.data('rte') || event.data;
if (rte && rte.$last && (!$editable.size() || rte.$last[0] != $editable[0])) {
var $destroy = rte.$last;
if (this && this.$last && (!$editable.size() || this.$last[0] != $editable[0])) {
var $destroy = this.$last;
history.splitNext();
setTimeout(function () {
@@ -519,15 +521,15 @@ var RTE = Widget.extend({
$destroy.destroy().removeData('note-id').removeAttr('data-note-id');
$('#note-popover-'+id+', #note-handle-'+id+', #note-dialog-'+id+'').remove();
},150); // setTimeout to remove flickering when change to editable zone (re-create an editor)
rte.$last = null;
this.$last = null;
}
if ($editable.size() && (!rte.$last || rte.$last[0] != $editable[0]) &&
if ($editable.size() && (!this.$last || this.$last[0] != $editable[0]) &&
($target.closest('[contenteditable]').attr('contenteditable') || "").toLowerCase() !== 'false') {
$editable.summernote(rte.config($editable));
$editable.summernote(this.config($editable));
$editable.data('NoteHistory', history);
rte.$last = $editable;
this.$last = $editable;
// firefox & IE fix
try {
@@ -547,7 +549,7 @@ var RTE = Widget.extend({
$target.trigger('mousedown'); // for activate selection on picture
}
rte.onEnableEditableArea($editable);
this.onEnableEditableArea($editable);
}
},
@@ -562,9 +564,9 @@ var RTE = Widget.extend({
return;
}
var rte = event.data;
var self = this;
setTimeout(function () {
rte.historyRecordUndo($target, 'activate', true);
self.historyRecordUndo($target, 'activate', true);
},0);
},