-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
202 lines (180 loc) · 5.49 KB
/
index.html
File metadata and controls
202 lines (180 loc) · 5.49 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TODO Tasks</title>
<link rel="stylesheet" href="style.css">
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #e8ebc9;
font-size: 1.2em;
}
h2 {
padding: 12px;
margin: 10px;
font-size: 32px;
background: #e3bfbf;
border-radius: 10px;
}
.center {
text-align: center;
}
.editor-container label {
font-size: 20px;
}
.editor-container input {
padding: 2px 6px;
font-size: 1.15em;
margin: 5px;
border-radius: 8px;
}
.editor-container textarea {
padding: 8px;
margin-top: 23px;
border-radius: 5px;
font-size: 1.2em;
}
.editor-container button {
padding: 4px;
margin-top: 5px;
font-size: 1em;
border-radius: 5px;
}
#notes-container {
margin: 2rem;
display: flex;
align-items: center;
justify-content: center;
background: #edf1b9;
border-radius: 8px;
flex-wrap: wrap;
}
.note {
position: relative;
flex: 250px;
max-width: 250px;
width: 250px;
padding: 10px;
padding-bottom: 45px;
margin: 10px;
font-family: cursive;
background: #fcfc64;
border: 1px solid black;
border-radius: 10px;
min-height: 230px;
box-shadow: 10px 10px 15px 0px #000000;
}
.note h3 {
border-bottom: 2px solid #000;
}
.note p{
overflow-y: auto;
}
.note button {
position: absolute;
float: right;
font-size: 1em;
padding: 5px;
border-radius: 5px;
bottom: 10px;
right: 10px;
}
footer {
position: relative;
bottom: 0;
background: black;
color: white;
width: 70%;
height: 23px;
padding: 10px;
overflow: hidden;
border-radius: 20px;
left: -25px;
padding-left: 85px;
font-size: 25px;
}
footer span {
color: #e3bfbf;
font-family: sans-serif;
}
</style>
</head>
<body>
<h2 class="center">TODO Tasks List</h2>
<div class="editor-container center">
<label for="title">Enter Title</label><br>
<input type="text" name="" id="title"><br>
<label for="editor">Write your task here</label><br>
<textarea name="" id="editor" cols="30" rows="10"></textarea><br>
<button id="add-note">Add To Task List</button>
</div>
<div id="notes-container">
</div>
<footer>
Developed by <span>Ali Amir</span>
</footer>
<script>
let notesArray = [];
window.onload = () => {
// Load notes on startup
notesArray = JSON.parse(localStorage.getItem('notes'));
if (notesArray == null) {
notesArray = [];
return
}
for (let i = 0; i < notesArray.length; i++) {
makeNote(notesArray[i]);
}
}
document.getElementById('add-note').addEventListener('click', () => {
//save note to localstorage
console.log('clicked');
let note = {
title: document.getElementById('title').value,
text: document.getElementById('editor').value
}
if(note.title === '' || note.text === ''){
return;
}
notesArray.push(note);
localStorage.setItem('notes', JSON.stringify(notesArray));
location.reload();
});
function makeNote(noteObj) {
let notesContainer = document.getElementById('notes-container');
let note = document.createElement('div');
let heading = document.createElement('h3');
let para = document.createElement('p');
let button = document.createElement('button');
button.setAttribute('class', 'remove-note');
button.setAttribute('onclick','removeNote(this.parentElement);');
heading.innerHTML = noteObj.title;
para.innerHTML = noteObj.text;
button.innerHTML = 'Done';
note.appendChild(heading);
note.appendChild(para);
note.appendChild(button);
note.setAttribute('class', 'note');
notesContainer.appendChild(note);
}
function removeNote(note){
let title = (note.childNodes)[0].innerHTML;
let text = (note.childNodes)[1].innerHTML;
for(let i = 0; i < notesArray.length; i++){
if(notesArray[i].title === title && notesArray[i].text === text){
notesArray.splice(i,1);
break;
}
}
localStorage.setItem('notes',JSON.stringify(notesArray));
location.reload();
}
</script>
</body>
</html>