@@ -63,6 +63,7 @@ class nestedSort {
63
63
}
64
64
65
65
this . maybeInitDataDom ( )
66
+ this . addListAttributes ( )
66
67
this . initDragAndDrop ( ) ;
67
68
}
68
69
@@ -83,20 +84,26 @@ class nestedSort {
83
84
if ( ! ( Array . isArray ( this . data ) && this . data . length ) ) return ;
84
85
85
86
const list = this . getDataEngine ( ) . render ( )
86
- list . classList . add ( ...this . listClassNames )
87
87
document . getElementById ( this . selector ) . appendChild ( list ) ;
88
88
}
89
89
90
- initDragAndDrop ( ) {
90
+ getSortableList ( ) {
91
+ if ( this . sortableList instanceof HTMLUListElement ) return this . sortableList
92
+ const list = document . getElementById ( this . selector )
93
+ this . sortableList = list . nodeName === 'UL' ? list : list . querySelector ( 'ul' )
94
+ return this . sortableList
95
+ }
96
+
97
+ addListAttributes ( ) {
98
+ this . getSortableList ( ) . classList . add ( ...this . listClassNames )
99
+ }
91
100
101
+ initDragAndDrop ( ) {
92
102
document . addEventListener ( 'dragover' , this . dragListener . bind ( this ) , false ) ;
93
103
94
104
this . initPlaceholderList ( ) ;
95
105
96
- const list = document . getElementById ( this . selector )
97
- this . sortableList = list . nodeName === 'UL' ? list : list . querySelector ( 'ul' )
98
-
99
- this . sortableList . querySelectorAll ( 'li' ) . forEach ( el => {
106
+ this . getSortableList ( ) . querySelectorAll ( 'li' ) . forEach ( el => {
100
107
el . setAttribute ( 'draggable' , 'true' ) ;
101
108
102
109
el . addEventListener ( 'dragstart' , this . onDragStart . bind ( this ) , false ) ;
@@ -164,7 +171,7 @@ class nestedSort {
164
171
this . cleanupPlaceholderLists ( ) ;
165
172
166
173
if ( typeof this . actions . onDrop === 'function' ) {
167
- this . actions . onDrop ( this . getDataEngine ( ) . convertDomToData ( this . sortableList ) )
174
+ this . actions . onDrop ( this . getDataEngine ( ) . convertDomToData ( this . getSortableList ( ) ) )
168
175
}
169
176
}
170
177
@@ -317,7 +324,7 @@ class nestedSort {
317
324
}
318
325
319
326
cleanupPlaceholderLists ( ) {
320
- this . sortableList . querySelectorAll ( 'ul' ) . forEach ( ul => {
327
+ this . getSortableList ( ) . querySelectorAll ( 'ul' ) . forEach ( ul => {
321
328
if ( ! ul . querySelectorAll ( 'li' ) . length ) {
322
329
ul . remove ( ) ;
323
330
} else if ( ul . classList . contains ( this . classNames . placeholder ) ) {
0 commit comments