diff options
| author | Christophe Matthieu <chm@odoo.com> | 2015-11-04 12:33:59 +0100 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2015-11-04 16:10:44 +0100 |
| commit | f3ade95862e5effa2b8cc46c8d953d84e1116495 (patch) | |
| tree | 0fe584f34401dd2bb192cb6623d527fb1b288d8f /addons/web_editor/static | |
| parent | c7ff7cb491274c4c2cedca7e0f02b7ba4fd654ca (diff) | |
[FIX] web_editor: use _.bind for rte handler to use 'this' and avoid errors
Diffstat (limited to 'addons/web_editor/static')
| -rw-r--r-- | addons/web_editor/static/src/js/rte.js | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js index a2833334085..c107ca342ae 100644 --- a/addons/web_editor/static/src/js/rte.js +++ b/addons/web_editor/static/src/js/rte.js @@ -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); }, |
