-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
140 lines (80 loc) · 2.45 KB
/
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var inpu = document.querySelector("input");
var inpuDisp = 1;
var inputdiv = document.querySelector("#input");
var plusButton = document.querySelector("#plusToDo");
var list = document.querySelector("#list");
var listCount = 0;
plusButton.addEventListener("click", function(){
if(inpuDisp==1){
$(inpu).fadeOut(200);
inpu.value = '';
inpuDisp = 0;
}
else{
$(inpu).fadeIn(300);
inpuDisp = 1;
}
});
function addToList( tod ){
var n = document.createElement("div");
if(listCount%2==0){
n.classList.add("itemOdd");
}
else
n.classList.add("itemEven");
listCount++;
var s = document.createElement("span");
s.classList.add("delete-button");
s.innerHTML = "<i class=\"fas fa-trash-alt smallButton\"></i>";
n.appendChild(s);
var s2 = document.createElement("span");
s2.classList.add("todoText");
s2.textContent = tod;
n.appendChild(s2);
var spans = n.childNodes;
spans[0].style.width = "0";
spans[0].style.opacity = "0";
n.addEventListener("mouseover", function(){
spans[0].style.width = "10%";
spans[0].style.opacity = "1";
});
n.addEventListener("mouseout", function(){
spans[0].style.width = "0";
spans[0].style.opacity = "0";
});
spans[0].addEventListener("click", function(){
var d = document.querySelector("#list").querySelectorAll("div");
var z;
for(var i=0; i<d.length; i++){
if(d[i] == n){
z = i;
}
}
$(n).fadeOut(500, function(){
for(var i = z +1; i<d.length; i++){
if(d[i].classList.contains("itemOdd")){
d[i].classList.remove("itemOdd");
d[i].classList.add("itemEven");
}
else{
d[i].classList.remove("itemEven");
d[i].classList.add("itemOdd");
}
}
n.remove();
})
listCount--;
});
spans[1].addEventListener("click", function(){
this.classList.toggle("done");
})
list.appendChild(n);
}
document.addEventListener("keypress", function(e){
if(e.keyCode == 13){
if(inpu.value != ''){
addToList(inpu.value);
inpu.value = '';
}
}
});