-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (59 loc) · 1.5 KB
/
index.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
let tasks=[]
const taskList=document.getElementById('list');
const taskInput=document.getElementById('add');
console.log('hehe');
function addToDom(task)
{
const li=document.createElement('li');
li.innerHTML=
`
<input type="checkbox" id="${task.id}" class="custom-checkbox">
<label for="${task.id}">${task.text}</label>
<box-icon name='message-alt-x' type='solid' color='#ba0a0a' class="delete" data-id="${task.id}"></box-icon>
<img src="./message-alt-x-solid-24.png" class="delete" data-id="12" />
`
taskList.append(li);
}
function renderList(){
taskList.innerHTML='';
for(let i=0;i<tasks.length;i++)
{
addToDom(tasks[i]);
}
}
function deleteTask(taskId){
let newTasks=tasks.filter(function(task){
return task.id!=taskId
})
tasks=newTasks;
renderList();
showNotification("Task deleted successfullly")
}
function addTask(task){
if(task){
tasks.push(task);
renderList();
showNotification("Task aded succesfully")
}
}
function showNotification(text){
alert(text)
}
function handleInput(e){
if(e.key==='Enter'){
const text=e.target.value;
if(!text){
showNotification("Empty ra pumks");
return;
}
const task={
text,
id:Date.now().toString(),
done:false
}
e.target.value=''
console.log(task);
addTask(task);
}
}
document.addEventListener('keyup',handleInput);