From 40795c00368677b643afb7c0f2ccea7dd2eeb2ee Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Fri, 20 Nov 2020 14:01:50 +0000 Subject: [PATCH] [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 X-original-commit: edf28efe19bedfe5eb62baf6fa5832a50d18e775 --- .../static/src/js/editor/snippets.editor.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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 58d387d1a33..af706e0c328 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -674,9 +674,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'); }); }, @@ -739,7 +744,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 @@ -2007,9 +2012,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'); }); @@ -2018,7 +2027,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();