-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (69 loc) · 2.38 KB
/
script.js
File metadata and controls
84 lines (69 loc) · 2.38 KB
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
77
78
79
80
81
82
83
84
var mainlist = document.getElementById("main__root-list") ;
var focusedlement ;
const upBtn =(e)=>{
var i =0 ;
var temp ;
const eventNode = e.target.parentNode ;
for(i ; eventNode!=mainlist.children[i] ; i++) ;
if(i != 0 ){
temp=mainlist.children[i];
if(temp.children[0] == document.activeElement){
mainlist.removeChild(temp);
mainlist.insertBefore(temp , mainlist.children[i-1]);
mainlist.children[i-1].children[0].focus();
}
else {
mainlist.removeChild(temp);
mainlist.insertBefore(temp , mainlist.children[i-1]);
}
}
else
console.log(`Beginng of the list !!`)
}
const downBtn = (e)=>{
var i = 0 ;
var temp ;
const eventNode = e.target.parentNode;
for(i ; mainlist.children[i]!=e.target.parentNode ; i ++);
if(mainlist.children[i+1]!=mainlist.lastchild) {
temp = mainlist.children[i];
if(temp.children[0] == document.activeElement){
mainlist.removeChild(temp);
mainlist.insertBefore(temp , mainlist.children[i+1]);
mainlist.children[i+1].children[0].focus();
}
else {
mainlist.removeChild(temp);
mainlist.insertBefore(temp , mainlist.children[i+1]);
}
}
else
console.log('End of the list !!')
}
const removeBtn = (e)=>{
mainlist.removeChild(e.target.parentNode);
}
const focused = (e)=>{
focusedlement = e.target.parentNode ;
console.log(focusedlement);
}
const add = (e)=> {
const container = document.createElement('div');
const input = document.createElement('input');
container.appendChild(input);
const up_btn = document.createElement('button');
up_btn.innerText="↑";
up_btn.addEventListener('click' , upBtn);
up_btn.addEventListener('mousedown', (e)=>{ e.preventDefault()})
container.appendChild(up_btn);
const down_btn = document.createElement('button');
down_btn.innerText="↓" ;
down_btn.addEventListener('click' , downBtn )
down_btn.addEventListener('mousedown', (e)=>{ e.preventDefault()})
container.appendChild(down_btn);
const remove_btn = document.createElement('button')
remove_btn.innerText="x"
remove_btn.addEventListener('click',removeBtn);
container.appendChild(remove_btn);
mainlist.prepend(container)
}