From 2bb33dfec5ed2fbef85dfa1b3d286b7f2151bc77 Mon Sep 17 00:00:00 2001 From: Richard Dubiel Date: Wed, 15 Dec 2021 22:46:28 -0600 Subject: [PATCH] Adds containment option to sortable plugin. --- src/plugins/sortable/plugin.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/sortable/plugin.js b/src/plugins/sortable/plugin.js index 1eeb9dab..1c8ca1f7 100644 --- a/src/plugins/sortable/plugin.js +++ b/src/plugins/sortable/plugin.js @@ -28,6 +28,7 @@ QueryBuilder.define('sortable', function(options) { var ghost; var src; var moved; + var containment = $(options.containment || document.body); // Init drag and drop this.on('afterAddRule afterAddGroup', function(e, node) { @@ -73,8 +74,8 @@ QueryBuilder.define('sortable', function(options) { }, onmove: function(event) { // make the ghost follow the cursor - ghost[0].style.top = event.clientY - 15 + 'px'; - ghost[0].style.left = event.clientX - 15 + 'px'; + ghost[0].style.top = event.clientY - containment.offset().top - 15 + 'px'; + ghost[0].style.left = event.clientX - containment.offset().left - 15 + 'px'; }, onend: function(event) { // starting from Interact 1.3.3, onend is called before ondrop