Skip to content

Commit

Permalink
[FIX] web_editor: put the snippet editor UI at the correct DOM position
Browse files Browse the repository at this point in the history
Commit odoo@4f27e52
had to instantiate the snippet editor UI differently but the hack broke
the position of the oe_manipulator which is supposed to be at the top
left of the editable zone.

closes odoo#39751

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
  • Loading branch information
qsm-odoo committed Nov 4, 2019
1 parent b8d7c69 commit 86d1270
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 1 addition & 3 deletions addons/web_editor/static/src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ var EditorMenuBar = Widget.extend({

// Snippets menu
if (self.snippetsMenu) {
// TODO improve this, the editor can be relocated so here,
// 'insertAfter(this.$el)' won't work.
defs.push(this.snippetsMenu.appendTo(this.$el.parent()));
defs.push(this.snippetsMenu.insertAfter(this.$el));
}
this.rte.editable().find('*').off('mousedown mouseup click');

Expand Down
20 changes: 19 additions & 1 deletion addons/web_editor/static/src/js/wysiwyg/wysiwyg_snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,32 @@ Wysiwyg.include({
this.editor = new (this.Editor)(this, this.options);
this.$editor = this.editor.rte.editable();
await this.editor.prependTo(this.$editor[0].ownerDocument.body);
this.options.toolbarHandler.append(this.editor.$el);
this._relocateEditorBar();
this.$el.on('content_changed', function (e) {
self.trigger_up('wysiwyg_change');
});
} else {
return this._super();
}
},

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* @private
*/
_relocateEditorBar: function () {
this.options.toolbarHandler.append(this.editor.$el);
// TODO the next four lines are a huge hack: since the editor.$el
// is repositioned, the snippetsMenu elements are not at the
// correct position anymore... the whole logic has to be refactored.
if (this.editor.snippetsMenu) {
this.editor.snippetsMenu.$el.insertAfter(this.options.toolbarHandler);
this.editor.snippetsMenu.$snippetEditorArea.insertAfter(this.editor.snippetsMenu.$el);
}
},
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var WysiwygTranslate = WysiwygMultizone.extend({
var promise = this.editor.prependTo(this.$editor[0].ownerDocument.body);

return promise.then(function () {
self.options.toolbarHandler.append(self.editor.$el);
self._relocateEditorBar();
var attrs = ['placeholder', 'title', 'alt'];
_.each(attrs, function (attr) {
self._getEditableArea().filter('[' + attr + '*="data-oe-translation-id="]').filter(':empty, input, select, textarea, img').each(function () {
Expand Down

0 comments on commit 86d1270

Please sign in to comment.