diff options
| author | qsm-odoo <qsm@odoo.com> | 2020-09-28 11:07:30 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-09-28 15:09:44 +0000 |
| commit | 0f65015b1b0a849bf109df11fd18a9e3a62820e4 (patch) | |
| tree | 69eff0a67396a6d186ee2593fc29186e687a105c /addons/web_editor/static/src/js/editor | |
| parent | 9dfb85b494efeec7786d345315977b9bcea63b82 (diff) | |
[FIX] web_editor, *: show text tools in style tab only
*: website
As the text editor is still the summernote one, this improvement was
made possible through a series of hack. It has to be reviewed once the
new editor is ready.
This makes the text tools only appear in the style tab by switching to
it as soon as the summernote tools are updated. To prevent flickering,
css and js hacks had to be made.
This also moves the undo/redo buttons in the top bar with another hack:
those simulates click on the hidden summernote ones.
Part of https://github.com/odoo/odoo/pull/58638
Diffstat (limited to 'addons/web_editor/static/src/js/editor')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/rte.summernote.js | 9 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 38 |
2 files changed, 43 insertions, 4 deletions
diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js index 229acc0616c..b99c9781446 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -341,6 +341,15 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) { } else { $airPopover.show(); } + + const $externalHistoryButtons = $('.o_we_external_history_buttons'); + if ($externalHistoryButtons.length) { + const $noteHistory = $('.note-history'); + $noteHistory.addClass('d-none'); + $externalHistoryButtons.find(':first-child').prop('disabled', $noteHistory.find('[data-event=undo]').prop('disabled')); + $externalHistoryButtons.find(':last-child').prop('disabled', $noteHistory.find('[data-event=redo]').prop('disabled')); + } + $popover.trigger('summernote_popover_update_call'); }; var fn_handle_update = eventHandler.modules.handle.update; 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 b4a5dca1d4b..707c73ed481 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -821,6 +821,7 @@ var SnippetsMenu = Widget.extend({ 'mousedown': '_onMouseDown', 'input .o_snippet_search_filter_input': '_onSnippetSearchInput', 'click .o_snippet_search_filter_reset': '_onSnippetSearchResetClick', + 'summernote_popover_update_call .o_we_snippet_text_tools': '_onSummernoteToolsUpdate', }, custom_events: { 'activate_insertion_zones': '_onActivateInsertionZones', @@ -929,7 +930,7 @@ var SnippetsMenu = Widget.extend({ this.customizePanel.classList.add('o_we_customize_panel', 'd-none'); this.textEditorPanelEl = document.createElement('div'); - this.textEditorPanelEl.classList.add('o_we_snippet_text_tools'); + this.textEditorPanelEl.classList.add('o_we_snippet_text_tools', 'd-none'); this.invisibleDOMPanelEl = document.createElement('div'); this.invisibleDOMPanelEl.classList.add('o_we_invisible_el_panel'); @@ -1030,9 +1031,8 @@ var SnippetsMenu = Widget.extend({ }); const $autoFocusEls = $('.o_we_snippet_autofocus'); - if ($autoFocusEls.length) { - this._activateSnippet($autoFocusEls.first()); - } + this._activateSnippet($autoFocusEls.length ? $autoFocusEls.first() : false); + this._textToolsSwitchingEnabled = true; return Promise.all(defs).then(() => { this.$('[data-title]').tooltip({ @@ -1985,6 +1985,7 @@ var SnippetsMenu = Widget.extend({ * @param {this.tabs.VALUE} [tab='blocks'] - the tab to select */ _updateLeftPanelContent: function ({content, tab}) { + clearTimeout(this._textToolsSwitchingTimeout); this._closeWidgets(); tab = tab || this.tabs.BLOCKS; @@ -1999,10 +2000,12 @@ var SnippetsMenu = Widget.extend({ this.$('.o_snippet_search_filter').toggleClass('d-none', tab !== this.tabs.BLOCKS); this.$('#o_scroll').toggleClass('d-none', tab !== this.tabs.BLOCKS); this.customizePanel.classList.toggle('d-none', tab === this.tabs.BLOCKS); + this.textEditorPanelEl.classList.toggle('d-none', tab !== this.tabs.OPTIONS); this.$('.o_we_add_snippet_btn').toggleClass('active', tab === this.tabs.BLOCKS); this.$('.o_we_customize_snippet_btn').toggleClass('active', tab === this.tabs.OPTIONS) .prop('disabled', tab !== this.tabs.OPTIONS); + }, /** * Scrolls to given snippet. @@ -2426,6 +2429,33 @@ var SnippetsMenu = Widget.extend({ }, /** * @private + */ + _onSummernoteToolsUpdate(ev) { + if (!this._textToolsSwitchingEnabled) { + return; + } + if (!$.summernote.core.range.create()) { + // Sometimes not enough... + return; + } + this.textEditorPanelEl.classList.add('d-block'); + const hasVisibleButtons = !!$(this.textEditorPanelEl).find('.btn:visible').length; + this.textEditorPanelEl.classList.remove('d-block'); + if (!hasVisibleButtons) { + // Ugly way to detect that summernote was updated but there is no + // visible text tools. + return; + } + // Only switch tab without changing content (_updateLeftPanelContent + // make text tools visible only on that specific tab). Also do it with + // a slight delay to avoid flickering doing it twice. + clearTimeout(this._textToolsSwitchingTimeout); + this._textToolsSwitchingTimeout = setTimeout(() => { + this._updateLeftPanelContent({tab: this.tabs.OPTIONS}); + }, 250); + }, + /** + * @private * @param {OdooEvent} ev */ _onUpdateCustomizeElements: function (ev) { |
