diff --git a/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js b/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js index 2cd8a74d1e1..a63b5232193 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_wysiwyg.js @@ -1,10 +1,8 @@ /** @odoo-module **/ import { loadBundle } from "@web/core/assets"; -import { attachComponent } from "@web/legacy/utils"; import { Wysiwyg } from "@web_editor/js/wysiwyg/wysiwyg"; import { closestElement } from "@web_editor/js/editor/odoo-editor/src/OdooEditor"; -import { Toolbar } from "@web_editor/js/editor/toolbar"; import "@web_editor/js/wysiwyg/wysiwyg_iframe"; export class MassMailingWysiwyg extends Wysiwyg { @@ -13,6 +11,11 @@ export class MassMailingWysiwyg extends Wysiwyg { //-------------------------------------------------------------------------- async startEdition() { + // The initial toolbar of the Wysiwyg component will be used as the + // mainToolbar (sticky on mobile and floating on desktop). + this.mainToolbarEl = this.toolbarRef.el.firstChild; + this.mainToolbarEl.classList.add('d-none'); + const res = await super.startEdition(...arguments); // Prevent selection change outside of snippets. this.$editable.on('mousedown', e => { @@ -38,48 +41,33 @@ export class MassMailingWysiwyg extends Wysiwyg { /** * Sets SnippetsMenu fold state and switches toolbar. - * Instantiates a new floating Toolbar if needed. + * Configures the main toolbar if needed. * * @param {Boolean} fold */ - async setSnippetsMenuFolded(fold = true) { - if (fold) { - this.snippetsMenu.setFolded(true); - if (!this.floatingToolbar) { - // The wysiwyg can be instanciated inside an iframe. The dialog - // component is mounted on the global document. - const toolbarWrapperElement = document.createElement('div'); - toolbarWrapperElement.style.display = 'contents'; - document.body.append(toolbarWrapperElement); - // Instantiate and configure new toolbar. - await attachComponent({}, toolbarWrapperElement, Toolbar, this.state.toolbarProps); - this.toolbarEl = toolbarWrapperElement.firstChild; - this.floatingToolbarEl = this.toolbarEl; - - this._configureToolbar({ snippets: false }); - this._updateEditorUI(); - this.setCSSVariables(this.toolbarEl); - this.odooEditor.setupToolbar(this.toolbarEl); - if (this.odooEditor.isMobile) { - document.body.querySelector('.o_mail_body').prepend(this.toolbarEl); - } else { - document.body.append(this.toolbarEl); - } + setSnippetsMenuFolded(fold = true) { + this.snippetsMenu.setFolded(fold); + this.toolbarEl = fold ? this.mainToolbarEl : this.snippetsMenuToolbarEl; + // At startup, the `SnippetMenu` set its toolbar before the + // `mainToolbarEl` had the chance to be configured. So we configure it + // now if we need it. + if (fold && !this._isMainToolbarReady) { + // Setup toolbar. + this._configureToolbar({ snippets: false }); + this._updateEditorUI(); + this.setCSSVariables(this.toolbarEl); + // Position the toolbar element. + if (this.odooEditor.isMobile) { + document.body.querySelector('.o_mail_body').prepend(this.toolbarEl); } else { - this.toolbarEl = this.floatingToolbarEl; - } - this.toolbarEl.classList.remove('d-none'); - this.odooEditor.autohideToolbar = true; - this.odooEditor.toolbarHide(); - } else { - this.snippetsMenu.setFolded(false); - this.toolbarEl = this.snippetsMenuToolbarEl; - - this.odooEditor.autohideToolbar = false; - if (this.floatingToolbarEl) { - this.floatingToolbarEl.classList.add('d-none'); + document.body.append(this.toolbarEl); } + this._isMainToolbarReady = true; } + this.odooEditor.toolbar = this.toolbarEl; + this.odooEditor.autohideToolbar = !!fold; + this.odooEditor.toolbarHide(); + this.mainToolbarEl.classList.toggle('d-none', !fold); } /** diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index cdbd7c9cbd4..cfde6e60f24 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1895,7 +1895,7 @@ var SnippetsMenu = Widget.extend({ const toolbarEl = this._toolbarWrapperEl.firstChild; toolbarEl.classList.remove('oe-floating'); - this.options.wysiwyg.toolbarEl.style.display = 'none'; + this.options.wysiwyg.toolbarEl.classList.add('d-none'); this.options.wysiwyg.setupToolbar(toolbarEl); this._addToolbar(); this._checkEditorToolbarVisibilityCallback = this._checkEditorToolbarVisibility.bind(this);