Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23105ef

Browse files
committed
Fixed a longstanding max child depth bug
1 parent b1084e2 commit 23105ef

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

jquery.nestedsortable.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ $.fn.nestedSortable = function(settings) {
5757
$this.hide().after($placeholder);
5858

5959
// Find the depth of the deepest nested child and cache it for later
60-
var maxChildDepth = 0;
61-
$this.find(settings.nestable).each(function(index, child) {
62-
var $child = $(child);
63-
var childDepth = $child.parentsUntil($this).filter(settings.nestable).length;
64-
if (childDepth > maxChildDepth) {
65-
maxChildDepth = childDepth;
66-
}
67-
});
68-
$this.data("maxChildDepth", maxChildDepth);
60+
if (settings.maxDepth) {
61+
var maxChildDepth = 0;
62+
$this.find(settings.nestable).each(function(index, child) {
63+
var $child = $(child);
64+
var childDepth = $child.parentsUntil($this).filter(settings.nestable).length;
65+
if (childDepth > maxChildDepth) {
66+
maxChildDepth = childDepth;
67+
}
68+
});
69+
$this.data("maxChildDepth", maxChildDepth);
70+
}
6971

7072
// Disable text selection
7173
if (settings.disableSelect) {
@@ -93,11 +95,11 @@ $.fn.nestedSortable = function(settings) {
9395
// Cycle through all nestables in this nested list looking for the one directly under the helper
9496
$root.find(settings.nestable).each(function(index, item) {
9597

96-
$item = $(item);
97-
itemOffset = $item.offset();
98+
var $item = $(item);
99+
var itemOffset = $item.offset();
98100

99101
// Is the item being checked below the one being dragged and above the previous lowest element?
100-
if (!((itemOffset.top < ui.position.top) && (itemOffset.top > largestY)))
102+
if (!((itemOffset.top > largestY) && (itemOffset.top < ui.position.top)))
101103
return;
102104

103105
// Is the item being checked on the right nesting level for the dragged item's horizantal position?
@@ -137,7 +139,7 @@ $.fn.nestedSortable = function(settings) {
137139
} else {
138140

139141
// Should the dragged item be nested?
140-
if (($underItem.offset().left + settings.indent - settings.snapTolerance < ui.position.left) && (settings.maxDepth === null || depth < settings.maxDepth)) {
142+
if (($underItem.offset().left + settings.indent - settings.snapTolerance < ui.position.left) && (!settings.maxDepth || depth < settings.maxDepth)) {
141143
$underItem.children(settings.container).prepend($placeholder);
142144

143145
// … or should it just be placed after

0 commit comments

Comments
 (0)