@@ -57,15 +57,17 @@ $.fn.nestedSortable = function(settings) {
57
57
$this . hide ( ) . after ( $placeholder ) ;
58
58
59
59
// 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
+ }
69
71
70
72
// Disable text selection
71
73
if ( settings . disableSelect ) {
@@ -93,11 +95,11 @@ $.fn.nestedSortable = function(settings) {
93
95
// Cycle through all nestables in this nested list looking for the one directly under the helper
94
96
$root . find ( settings . nestable ) . each ( function ( index , item ) {
95
97
96
- $item = $ ( item ) ;
97
- itemOffset = $item . offset ( ) ;
98
+ var $item = $ ( item ) ;
99
+ var itemOffset = $item . offset ( ) ;
98
100
99
101
// 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 ) ) )
101
103
return ;
102
104
103
105
// 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) {
137
139
} else {
138
140
139
141
// 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 ) ) {
141
143
$underItem . children ( settings . container ) . prepend ( $placeholder ) ;
142
144
143
145
// … or should it just be placed after
0 commit comments