[FIX] web_editor: fix scroll event on snippet popup

Before this commit, when scrolling a snippet popup, the overlay was
not updating its position.

So now, we use addEventListener instead of jQuery for the scroll event
on the scrolling element because we need the 'capture' parameter.
Setting this capture parameter to true allows us to take advantage of
event bubbling for events that otherwise don’t support it.

Part of https://github.com/odoo/odoo/pull/61998
task-2312878

X-original-commit: e734df614a07d51cfd2c9eb6e3876189e1d22a69
Co-authored-by: Samuel Degueldre <sad@odoo.com>
This commit is contained in:
Benjamin Vray
2021-01-27 17:48:23 +00:00
committed by qsm-odoo
co-authored by Samuel Degueldre
parent 9e01297c67
commit 1fa874a885
@@ -1074,7 +1074,7 @@ var SnippetsMenu = Widget.extend({
// Hide the active overlay when scrolling.
// Show it again and recompute all the overlays after the scroll.
this.$scrollingElement = $().getScrollingElement();
this.$scrollingElement.on('scroll.snippets_menu', _.throttle(() => {
this._onScrollingElementScroll = _.throttle(() => {
for (const editor of this.snippetEditors) {
editor.toggleOverlayVisibility(false);
}
@@ -1086,7 +1086,12 @@ var SnippetsMenu = Widget.extend({
editor.cover();
}
}, 250);
}, 50));
}, 50)
// We use addEventListener instead of jQuery because we need 'capture'.
// Setting capture to true allows to take advantage of event bubbling
// for events that otherwise don’t support it. (e.g. useful when
// scrolling a modal)
this.$scrollingElement[0].addEventListener('scroll', this._onScrollingElementScroll, {capture: true});
// Auto-selects text elements with a specific class and remove this
// on text changes
@@ -1151,7 +1156,7 @@ var SnippetsMenu = Widget.extend({
this.$snippetEditorArea.remove();
this.$window.off('.snippets_menu');
this.$document.off('.snippets_menu');
this.$scrollingElement.off('.snippets_menu');
this.$scrollingElement[0].removeEventListener('scroll', this._onScrollingElementScroll, {capture: true});
}
core.bus.off('deactivate_snippet', this, this._onDeactivateSnippet);
delete this.cacheSnippetTemplate[this.options.snippets];