-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
156 lines (136 loc) · 4.23 KB
/
app.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//Made by Erfanhanifezade@gmail.com
//Selectors
const button = document.querySelector('.add-list-button');
const parag = document.querySelector('.input-text');
const todoContainer = document.querySelector('.todo-container');
const ul = document.querySelector(".ul-todo");
const filterOption = document.querySelector(".filter");
const btnClear = document.getElementById("clearbtn");
const arrOption = Array.from(filterOption.options);
//Add Events
button.addEventListener("click" , add);
btnClear.addEventListener("click" , clear);
filterOption.addEventListener("click" , filter);
//add opacity 0 , pointer events none to btn clear
if(ul.childElementCount <= 0)
{
btnClear.style.cssText = `opacity: 0; pointer-events: none`;
}
//Function
function add(event)
{
event.preventDefault();
const div = document.createElement('div');
div.classList.add('div-container');
div.classList.add("no-completed");
div.addEventListener("click" , check);
const li = document.createElement('li');
li.classList.add('li-element');
li.innerHTML = parag.value;
parag.value = " ";
div.appendChild(li);
const btnCheck = document.createElement('button');
btnCheck.classList.add("btn-check");
btnCheck.innerHTML = '<i class="fas fa-check"></i>';
div.appendChild(btnCheck);
const btnDel = document.createElement('button');
btnDel.innerHTML = '<i class="fas fa-trash"></li>';
btnDel.classList.add('btn-delete');
div.appendChild(btnDel);
ul.appendChild(div);
//Add opacity 1 , pointer event to clear btn
btnClear.style.cssText = `opacity: 1; pointer-events: all;`;
}
//clear function for clear list
function clear()
{
ul.innerHTML = "";
let para = document.createElement("h2");
ul.appendChild(para);
para.innerHTML = "Clear Completed!";
para.style.cssText = `color: white;`;
anime(
{
targets: para,
scale: [0 , 1],
duration: 1000,
easing: 'easeInOutExpo'
}
);
setTimeout(()=>{
anime(
{
targets: para,
scale: [1 , 0],
duration: 2000,
easing: 'easeInOutExpo'
}
);
} , 3000);
setTimeout(()=>{
ul.removeChild(para);
} , 5000);
}
//check function for btn check and delete
function check(btn)
{
const element = btn.target;
if(element.classList[0] === "btn-delete")
{
const dad = element.parentElement;
dad.classList.add("transition-btn");
dad.addEventListener("transitionend" , function(){
dad.style.dispaly = "none";
dad.remove();
});
}
if(element.classList[0] === "btn-check")
{
element.classList.add("bc");
const father = element.parentElement;
father.classList.add("completed");
father.classList.toggle("no-completed");
}
}
//filter function select/option
function filter(e)
{
if(ul.children.length >= 1)
{
const divs = Array.from(ul.children);
divs.forEach(item =>{
let cls = item.classList;
cls.forEach(clas =>{
switch(e.target.value)
{
case "all":
if(clas == "div-container")
{
item.style.cssText = `display: flex`;
}
break;
case "com":
if(clas == "completed")
{
item.style.cssText = `display: flex`;
}
if(clas == "no-completed")
{
item.style.cssText = `display: none`;
}
break;
case "nocom":
if(clas == "no-completed")
{
item.style.cssText = `display: flex`;
}
if(clas == "completed")
{
item.style.cssText = `display: none`;
}
break;
}
});
});
}
}