-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrows.js
77 lines (50 loc) · 1.94 KB
/
rows.js
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
67
68
69
70
71
72
73
74
75
76
let colors=["#FF7F7F","#FFBF7F","#FFDF7F","#FFFF7F","#BFFF7F","#7FFF7F","#7FFFFF","#7FBFFF","#7F7FFF","#FF7FFF","#BF7FBF","#3B3B3B","#858585","#F7F7F7"]
let rowName = ["S","A","B","C","D","F"]
const rows = document.querySelectorAll(".row");
tableBody = document.getElementById("tableBody")
function createRow(){
for(let i = 0 ; i<rowName.length ;i++){
tableBody.innerHTML += `
<tr class="draggable" draggable="true" >
<td>
<div class="row" >
<div style="background-color:${colors[i]};" class="label">${rowName[i]}</div>
</div>
</td>
<td>
<button class='settingsBtn'><i class="fa fa-gear" aria-hidden="true"></i> </button>
</td>
<td>
<button class='moveUpBtn'> <i class="fa fa-chevron-up" aria-hidden="true"></i></button> <br>
<button class='moveDownBtn'><i class="fa fa-chevron-down" aria-hidden="true"></i></button>
</td>
</tr>
`
}
}
createRow();
onClickMove();
function onClickMove(){
var moveUpBtn = [...document.getElementsByClassName("moveUpBtn")]
var moveDownBtn = [...document.getElementsByClassName("moveDownBtn")]
moveUpBtn.forEach(e => {
e.addEventListener("click",ChangePositionUp)
})
moveDownBtn.forEach(e=> {
e.addEventListener("click",ChangePositionDown)
})
}
function ChangePositionUp(){
currentElement = this.parentElement.parentElement;
previousElement = currentElement.previousElementSibling;
if(previousElement != null){
tableBody.insertBefore(currentElement,previousElement);
}
}
function ChangePositionDown(){
currentElement = this.parentElement.parentElement;
nextElement = currentElement.nextElementSibling;
if(nextElement != null){
tableBody.insertBefore(nextElement,currentElement);
}
}