-
Notifications
You must be signed in to change notification settings - Fork 1
/
src.js
147 lines (130 loc) · 3.61 KB
/
src.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
// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
onkeydown = (event) => {
let inputId = document.getElementById("subbtn");
let value = inputId.value;
if (event.key == "Enter" && value != "") {
newElement();
}
};
function chngplahldr() {
document.getElementById("myInput").placeholder = randomtext();
}
function rechgpldr() {
document.getElementById("myInput").placeholder = "Add a task...";
}
function randomtext() {
var random = Math.floor(Math.random() * 3);
let arr = [
"Try typing 'Pay utilities bill by Friday 6pm'",
"Try typing 'Pay Electricity bill by on Monday'",
"Bring Bananas from Market",
];
return arr[random];
}
let days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
let months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
let currdate = new Date().getDate();
let currmonth = new Date().getMonth();
let currday = new Date().getDay();
const content = document.createTextNode(
days[currday] + "," + " " + currdate + " " + months[currmonth]
);
let ins = document.getElementsByClassName("date")[0];
ins.appendChild(content);
// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
var count =0;
for (i = 0; i < close.length; i++) {
close[i].onclick = function () {
var div = this.parentElement;
div.parentNode.removeChild(div);
check();
}
}
function check(){
var num = document.getElementById("myUL").childElementCount;
// console.log(num);
if(num ==0){
// console.log("success");
document.getElementsByClassName("image")[0].style.display = "block";
document.getElementById("myUL").style.display = "none";
}
}
const elem = document.getElementById("myUL").childElementCount;
// console.log(elem);
// Add a "checked" symbol when clicking on a list item
var list = document.querySelector("ul");
list.addEventListener(
"click",
function (ev) {
if (ev.target.tagName === "LI") {
ev.target.classList.toggle("checked");
}
},
false
);
// Create a new list item when clicking on the "Add" button
function newElement() {
document.getElementsByClassName("image")[0].style.display = "none";
document.getElementById("myUL").style.display = "block";
count++;
// console.log(count);
var li = document.createElement("li");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === "") {
alert("You must write something!");
} else {
document.getElementById("myUL").prepend(li);
}
document.getElementById("myInput").value = "";
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
for (i = 0; i < close.length; i++) {
close[i].onclick = function () {
var div = this.parentElement;
div.parentNode.removeChild(div);
check();
};
}
}
//Clearing the list
function removeAll() {
var lst = document.getElementsByTagName("ul");
lst[0].innerHTML = "";
}