From edf28efe19bedfe5eb62baf6fa5832a50d18e775 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Fri, 20 Nov 2020 14:01:50 +0000 Subject: [FIX] web_editor: fix scroll during dragging a snippet in a modal Before this commit, it was not possible to scroll a popup with a dragged snippet. Part of https://github.com/odoo/odoo/pull/61998 task-2312878 --- .../web_editor/static/src/js/editor/snippets.editor.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'addons/web_editor/static/src') 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 0ebf68345e1..a67f45b3dc0 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -666,9 +666,14 @@ var SnippetEditor = Widget.extend({ } }, }); + + // If a modal is open, the scroll target must be that modal + const $openModal = self.$editable.find('.modal:visible'); + self.draggableComponent.$scrollTarget = $openModal.length ? $openModal : self.$scrollingElement; + // Trigger a scroll on the draggable element so that jQuery updates // the position of the drop zones. - this.$scrollingElement.on('scroll.scrolling_element', function () { + self.draggableComponent.$scrollTarget.on('scroll.scrolling_element', function () { self.$el.trigger('scroll'); }); }, @@ -731,7 +736,7 @@ var SnippetEditor = Widget.extend({ this.trigger_up('drag_and_drop_stop', { $snippet: this.$target, }); - this.$scrollingElement.off('scroll.scrolling_element'); + this.draggableComponent.$scrollTarget.off('scroll.scrolling_element'); }, /** * @private @@ -2015,9 +2020,13 @@ var SnippetsMenu = Widget.extend({ }, }); + // If a modal is open, the scroll target must be that modal + const $openModal = self.getEditableArea().find('.modal:visible'); + self.draggableComponent.$scrollTarget = $openModal.length ? $openModal : $scrollingElement; + // Trigger a scroll on the draggable element so that jQuery updates // the position of the drop zones. - $scrollingElement.on('scroll.scrolling_element', function () { + self.draggableComponent.$scrollTarget.on('scroll.scrolling_element', function () { self.$el.trigger('scroll'); }); @@ -2026,7 +2035,7 @@ var SnippetsMenu = Widget.extend({ }, stop: async function (ev, ui) { $toInsert.removeClass('oe_snippet_body'); - $scrollingElement.off('scroll.scrolling_element'); + self.draggableComponent.$scrollTarget.off('scroll.scrolling_element'); if (!dropped && ui.position.top > 3 && ui.position.left + ui.helper.outerHeight() < self.el.getBoundingClientRect().left) { var $el = $.nearest({x: ui.position.left, y: ui.position.top}, '.oe_drop_zone', {container: document.body}).first(); -- cgit v1.2.3