-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtodo_script.js
116 lines (89 loc) · 3.67 KB
/
todo_script.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
let input = document.getElementById('input');
let inputbtn = document.getElementById('inputbtn');
let todo = document.getElementById('todo');
let todoVals = [];
let html = ``;
function editTodo(todoId) {
let a = localStorage.getItem('todos');
if (document.getElementById(todoId).firstChild.data == 'Edit') {
window.m = document.getElementById(`${todoId}d2`).value
document.getElementById(`${todoId}d2`).disabled = false;
document.getElementById(`${todoId}d2`).focus()
document.getElementById(todoId).firstChild.data = 'Save';
}
else{
document.getElementById(`${todoId}d2`).disabled = true;
let old = a.indexOf(m)
n = document.getElementById(`${todoId}d2`).value
document.getElementById(`${todoId}d2`).value = n
console.log(n.length,n,old)
let b = a.replace(m,n)
console.log(b);
localStorage.setItem('todos',b)
document.getElementById(todoId).firstChild.data = 'Edit';
}
}
window.onload = function() {
input.focus();
}
if (localStorage.getItem('todos')[0] != null && localStorage.getItem('todos')[0] != "") {
todoVals.push(localStorage.getItem('todos').split(','))
for (let i = 0; i < todoVals[0].length; i++) {
console.log(i);
html = `<div class="body container mt-2" id='${todoVals[0][i]}id'>
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" value=""
aria-label="Radio button for following text input" id="${todoVals[0][i]}" onClick="deleteToDo(this.id)">
</div>
<input type="text" class="form-control" aria-label="Text input with radio button" value="${todoVals[0][i]}" id="${todoVals[0][i]}id2" disabled><button type="button" id="${todoVals[0][i]}i" class="btn btn-primary" onClick="editTodo(this.id)">Edit</button>
</div>
</div>`;
todo.innerHTML += html;
}
}
function getToDoVal() {
let todoVal = input.value;
if (todoVal != "") {
html = `<div class="body container mt-2" id='${todoVal}id'>
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" value=""
aria-label="Radio button for following text input" id="${todoVal}" onClick="deleteToDo(this.id)">
</div>
<input type="text" class="form-control" aria-label="Text input with radio button" value="${todoVal}" disabled>
</div>
</div>`;
todo.innerHTML += html;
todoVals.push(todoVal);
localStorage.setItem(`todos`, todoVals);
input.value = "";
location.reload();
}
else{
input.focus();
}
}
function deleteToDo(todoValue) {
console.log(todoValue);
document.getElementById(`${todoValue}id`).style.visibility = "hidden";
todoVals = todoVals[0].filter(function(item) {
return item !== todoValue
})
localStorage.setItem('todos',todoVals);
location.reload();
}
function deleteAllToDo(){
let confirmation = confirm('Do You Want To Delete All Tasks')
if (confirmation == true) {
todo.innerHTML = "";
todoVals = []
localStorage.setItem('todos',todoVals)
}
}
input.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("inputbtn").click();
}
});