-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
108 lines (106 loc) · 4 KB
/
Copy pathapp.js
File metadata and controls
108 lines (106 loc) · 4 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
let myInput=document.getElementById('myInput')
let tasksArea=document.querySelector('#myOl')
let number=0;
let arr=[];
let id=0
function showfilterbtn(){
document.getElementById('filterbtn').style.backgroundImage='url(/images/filterdowndark.svg)'
}
function taskcount(){
console.log(document.getElementById('myOl'))
if(document.getElementById('draggable').innerHTML==null){
document.querySelector('input').style.display='flex'
document.getElementById('myOl').style.display='none'
}
}
//clear input
document.querySelector('.clear').addEventListener('click',function(event){
event.preventDefault();
document.querySelector('input').value=''
})
//show input
function showInput(){
document.querySelector('form').style.display='flex'
document.querySelector('form').style.justifyContent='space-between'
document.querySelector('form').style.flexDirection='row'
document.querySelector('input').focus()
document.getElementById('myOl').scrollTop=document.getElementById('myOl').scrollHeight+3
}
document.querySelector('#submit').addEventListener("click", showInput)
//adding ol;
document.querySelector('input').addEventListener("keydown",function(event){
if(event.keyCode===13){
if(document.querySelector('input').value.length== 0){
alert('Please enter something')
}
else{
id+=1
number+=1
console.log(number)
document.querySelector('form').style.display='none'
document.getElementById('myOl').style.display='flex'
event.preventDefault()
tasksArea.innerHTML += `
<li draggable="true">
${document.querySelector('input').value}
<button class="delete">X
</button>
</li>
`;
document.querySelector('input').value=''
var current_tasks = document.querySelectorAll(".delete");
for(var i=0; i<current_tasks.length; i++){
current_tasks[i].onclick = function(){
this.parentNode.remove();
console.log(document.getElementById('myOl').childElementCount)
if(document.getElementById('myOl').childElementCount==0){
document.querySelector('form').style.display='flex'
document.getElementById('myOl').style.display='none'
}
}
}
}
}
})
// drag and drop
new Sortable(tasksArea,{
animation: 250
});
//sorting the elements
document.querySelector('#filterbtn').addEventListener('click', sortListDir)
function sortListDir() {
var list, i, switching, b, shouldSwitch, dir, switchcount = 0;
list = document.getElementById("myOl");
switching = true;
dir = "asc";
while (switching) {
switching = false;
b = list.getElementsByTagName('LI');
for (i = 0; i < (b.length - 1); i++) {
shouldSwitch = false;
if (dir == "asc") {
if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) {
shouldSwitch = true;
document.getElementById('down').setAttribute('class', 'fa-solid fa-arrow-up-wide-short')
break;
}
} else if (dir == "desc") {
document.getElementById('down').setAttribute('class', 'fa-solid fa-arrow-down-wide-short')
if (b[i].innerHTML.toLowerCase() < b[i + 1].innerHTML.toLowerCase()) {
shouldSwitch= true;
break;
}
}
}
if (shouldSwitch) {
b[i].parentNode.insertBefore(b[i + 1], b[i]);
switching = true;
switchcount ++;
} else {
if (switchcount == 0 && dir == "asc") {
dir = "desc";
switching = true;
}
}
}
}