-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (56 loc) · 2.41 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Draggable Nestable List</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="dist/DraggableNestableList.min.css">
<script src="data.js"></script>
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-8">
<ul id="myList" class="list-group"></ul>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="dist/DraggableNestableList.js"></script>
<script>
var orderList =[];
appendMenus($("#myList"), json);
let dnl = new DraggableNestableList("#myList");
getUpdatedOrder(document.getElementById("myList"));
console.log(orderList);
function appendMenus(parent, menu) {
for (var i = 0; i < menu.length; i++) {
var submenu = parent.append('<li class="list-group-item">'+
'<span class="material-icons dnl-grab-icon">'+menu[i].icon+'</span>'+
'<span class="dnl-item" data-id="' + menu[i].mid + '">' + menu[i].name + '</span></li>')
.find("li:last");
if (menu[i].children != undefined && menu[i].children.length > 0) {
submenu = submenu.append('<ul class="list-group"></ul>').find("ul");
appendMenus(submenu, menu[i].children);
}
}
}
function getUpdatedOrder(ul) {
var items = ul.children;
for (var i = 0; i < items.length; i++) {
var item = items[i];
var index = item.querySelector('.dnl-index').innerHTML;
var id = item.querySelector('.dnl-item').getAttribute("data-id");
var text = item.querySelector('.dnl-item').textContent;
orderList.push({id, text, order:index})
if (item.querySelector("ul")) {
getUpdatedOrder(item.querySelector("ul"));
}
}
}
</script>
</body>
</html>