Skip to content

Commit ede4e13

Browse files
author
Hesam Bahrami (Genzo)
committed
Merge branch 'release/2.3'
2 parents 00dae0f + 6aec8a6 commit ede4e13

File tree

5 files changed

+34
-266
lines changed

5 files changed

+34
-266
lines changed

dev/css/main.css

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,28 @@ body {
22
font-family: 'Roboto', sans-serif;
33
}
44

5-
.nested-sort,
6-
#draggable {
5+
.nested-sort {
76
padding: 0;
87
}
98

10-
.nested-sort li,
11-
#draggable li {
9+
.nested-sort li {
1210
list-style: none;
1311
margin: 0 0 5px;
1412
padding: 10px;
1513
background-color: #eee;
1614
border: 1px solid #ccc;
1715
}
1816

19-
.nested-sort li ul,
20-
#draggable li ul {
17+
.nested-sort li ul {
2118
padding: 0;
2219
margin-top: 10px;
2320
margin-bottom: -5px;
2421
}
2522

26-
.nested-sort .ns-dragged,
27-
#draggable .ns-dragged {
23+
.nested-sort .ns-dragged {
2824
outline: 2px solid red;
2925
}
3026

31-
.nested-sort .ns-targeted,
32-
#draggable .ns-targeted {
27+
.nested-sort .ns-targeted {
3328
outline: 2px solid green;
3429
}

dev/server-rendered-list.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ <h1>A server-rendered lists</h1>
4444
}
4545
},
4646
el: 'draggable',
47-
droppingEdge: 5
47+
droppingEdge: 5,
48+
listClassNames: ['nested-sort']
4849
});
4950
})();
5051
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nested-sort",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"author": "Hesam Bahrami (Genzo)",
55
"description": "A JavaScript library to create a nested list of elements",
66
"main": "dist/nested-sort.cjs.js",

src/main.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class nestedSort {
6363
}
6464

6565
this.maybeInitDataDom()
66+
this.addListAttributes()
6667
this.initDragAndDrop();
6768
}
6869

@@ -83,20 +84,26 @@ class nestedSort {
8384
if (!(Array.isArray(this.data) && this.data.length)) return;
8485

8586
const list = this.getDataEngine().render()
86-
list.classList.add(...this.listClassNames)
8787
document.getElementById(this.selector).appendChild(list);
8888
}
8989

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+
}
91100

101+
initDragAndDrop() {
92102
document.addEventListener('dragover', this.dragListener.bind(this), false);
93103

94104
this.initPlaceholderList();
95105

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 => {
100107
el.setAttribute('draggable', 'true');
101108

102109
el.addEventListener('dragstart', this.onDragStart.bind(this), false);
@@ -164,7 +171,7 @@ class nestedSort {
164171
this.cleanupPlaceholderLists();
165172

166173
if (typeof this.actions.onDrop === 'function') {
167-
this.actions.onDrop(this.getDataEngine().convertDomToData(this.sortableList))
174+
this.actions.onDrop(this.getDataEngine().convertDomToData(this.getSortableList()))
168175
}
169176
}
170177

@@ -317,7 +324,7 @@ class nestedSort {
317324
}
318325

319326
cleanupPlaceholderLists() {
320-
this.sortableList.querySelectorAll('ul').forEach(ul => {
327+
this.getSortableList().querySelectorAll('ul').forEach(ul => {
321328
if (!ul.querySelectorAll('li').length) {
322329
ul.remove();
323330
} else if (ul.classList.contains(this.classNames.placeholder)) {

0 commit comments

Comments
 (0)