summaryrefslogtreecommitdiff
path: root/addons/web_editor
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-09-17 10:41:10 +0000
committerqsm-odoo <qsm@odoo.com>2020-09-22 08:29:11 +0000
commit4e7be69825163c0a0ff41c882a196fc7f3158fb3 (patch)
tree517a928cddbfa019033af95f2f284cab4e82496d /addons/web_editor
parent416b125803d043badef8e4b022c100e33d1dba04 (diff)
[IMP] website, *: move page scrollbar to #wrapwrap
*: web, web_editor, portal, account, website_blog, website_forum This is probably not ideal to move the scrolling behavior out of the html element but this will be needed for the editor to not have a double scrollbar on the right. This is actually also useful for the scrollbar to appear under the purple odoo menu instead of its right. This commit, if to be reverted in the future, however contains many improvements to make the transition easier that should be kept: jQuery and Odoo functions to be able to scrollTo a specific element, get the top scrollable element, check if an element is scrollable, etc. Also, some magic was done: if some code tries to scroll to a specific scroll position via jQuery's scrollTop or animate functions on the html/body element, those will still work as intended (obviously, using the new utils to do that is however recommended). This commit also reviews our scroll behaviors to make them more robust and share the code. Part of https://github.com/odoo/odoo/pull/57975 task-2344227
Diffstat (limited to 'addons/web_editor')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.editor.js41
1 files changed, 10 insertions, 31 deletions
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 aa5bdd867e9..ecebf152f9d 100644
--- a/addons/web_editor/static/src/js/editor/snippets.editor.js
+++ b/addons/web_editor/static/src/js/editor/snippets.editor.js
@@ -100,7 +100,7 @@ var SnippetEditor = Widget.extend({
},
},
});
- this.draggableComponent = new SmoothScrollOnDrag(this, this.$el, $('html'), smoothScrollOptions);
+ this.draggableComponent = new SmoothScrollOnDrag(this, this.$el, $().getScrollingElement(), smoothScrollOptions);
} else {
this.$('.o_overlay_move_options').addClass('d-none');
$customize.find('.oe_snippet_clone').addClass('d-none');
@@ -997,8 +997,8 @@ var SnippetsMenu = Widget.extend({
// Hide the active overlay when scrolling.
// Show it again and recompute all the overlays after the scroll.
- // TODO: current limitation, suppose that this is the body which scrolls
- this.$document.on('scroll.snippets_menu', _.throttle(() => {
+ this.$scrollingElement = $().getScrollingElement();
+ this.$scrollingElement.on('scroll.snippets_menu', _.throttle(() => {
for (const editor of this.snippetEditors) {
editor.toggleOverlayVisibility(false);
}
@@ -1054,6 +1054,7 @@ var SnippetsMenu = Widget.extend({
this.$snippetEditorArea.remove();
this.$window.off('.snippets_menu');
this.$document.off('.snippets_menu');
+ this.$scrollingElement.off('.snippets_menu');
}
core.bus.off('deactivate_snippet', this, this._onDeactivateSnippet);
delete this.cacheSnippetTemplate[this.options.snippets];
@@ -1778,13 +1779,6 @@ var SnippetsMenu = Widget.extend({
*/
_getScrollOptions(options = {}) {
return Object.assign({}, options, {
- offsetElements: Object.assign({
- $top: $('#web_editor-top-edit'), // TODO should ideally be retrieved another way
- $left: this.$el,
- }, options.offsetElements),
- scrollBoundaries: Object.assign({
- left: false,
- }, options.scrollBoundaries),
jQueryDraggableOptions: Object.assign({
appendTo: this.$body,
cursor: 'move',
@@ -1954,7 +1948,7 @@ var SnippetsMenu = Widget.extend({
},
},
});
- this.draggableComponent = new SmoothScrollOnDrag(this, $snippets, $('html'), smoothScrollOptions);
+ this.draggableComponent = new SmoothScrollOnDrag(this, $snippets, $().getScrollingElement(), smoothScrollOptions);
},
/**
* Adds the 'o_default_snippet_text' class on nodes which contain only
@@ -2005,29 +1999,14 @@ var SnippetsMenu = Widget.extend({
.prop('disabled', tab !== this.tabs.OPTIONS);
},
/**
- * Scroll to the dropped snippet.
+ * Scrolls to given snippet.
*
* @private
- * @param {jQuery} [$el] - dropped snippet
- * @param {integer} [scrollValue] - scrollValue
+ * @param {jQuery} $el - snippet to scroll to
+ * @return {Promise}
*/
- _scrollToSnippet: function ($el, scrollValue) {
- // return if it's an inner snippet or if it's dropped in a modal
- if ($el.get(0).tagName.toLowerCase() !== 'section' || $el.parent().find("[class^='modal-']").length) {
- return Promise.resolve();
- }
- let headerHeight = 0;
- _.each($('.o_top_fixed_element'), el => headerHeight += $(el).outerHeight());
- return new Promise(resolve => {
- $('html, body').animate(
- {
- scrollTop: scrollValue - headerHeight - 50,
- },
- 700,
- 'swing',
- resolve,
- );
- });
+ async _scrollToSnippet($el) {
+ return dom.scrollTo($el[0], {extraOffset: 50});
},
/**
* @private