-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
177 lines (172 loc) · 5.81 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0"
/>
<link rel="stylesheet" href="bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<title>Note App</title>
</head>
<body>
<div>
<!-- For enter note press ENTER or click on the ADD button
For remove note click on itself -->
<!-- INPUT -->
<section id="home">
<div class="container">
<div class="header upper">Note App with capturing event</div>
<br /><br />
<div class="flex row-gt-sm">
<div class="flex flex-50-gt-sm">
<div
class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 mx-auto"
>
<input
id="input-field"
class="form-control"
type="text"
placeholder="Something here.."
onkeypress="addNoteWithKey(event)"
/>
</div>
<div
class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 mx-auto"
>
<div id="color-select">
<div class="color-box" style="background-color: #fff"></div>
<div
class="color-box"
style="background-color: #ffd37f"
></div>
<div
class="color-box"
style="background-color: #fffa81"
></div>
<div
class="color-box"
style="background-color: #d5fa80"
></div>
<div
class="color-box"
style="background-color: #78f87f"
></div>
<div
class="color-box"
style="background-color: #79fbd6"
></div>
<div
class="color-box"
style="background-color: #79fdfe"
></div>
<div
class="color-box"
style="background-color: #7ad6fd"
></div>
<div
class="color-box"
style="background-color: #7b84fc"
></div>
<div
class="color-box"
style="background-color: #d687fc"
></div>
<div
class="color-box"
style="background-color: #ff89fd"
></div>
</div>
</div>
<div
class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 mx-auto my-1 text-right"
>
<button
id="btn-save"
type="button"
class="btn btn-outline-info"
onclick="addNote()"
>
<span class="material-symbols-outlined"> add </span>
</button>
<button
id="btn-delete"
type="button"
class="btn btn-outline-danger"
onclick="clearInput()"
>
<span class="material-symbols-outlined">
auto_fix_normal
</span>
</button>
</div>
</div>
</div>
<!-- TASKS -->
<div class="flex row-gt-sm">
<div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<div class="container">
<div class="row">
<div
id="listed"
class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 p-3 card-columns"
></div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<script>
let inputElem = document.querySelector("#input-field");
let noteContainer = document.querySelector("#listed");
let addBtn = document.querySelector("#btn-save");
let removeBtn = document.querySelector("#btn-delete");
let colorBox = document.querySelectorAll(".color-box");
function createNote(data) {
let newPElem = document.createElement("p");
newPElem.className = "card-text p-3";
newPElem.innerHTML = data;
let newDivElem = document.createElement("div");
newDivElem.className = "card shadow-sm rounded";
newDivElem.style.backgroundColor = inputElem.style.backgroundColor;
// newDivElem.addEventListener("click", removeNote);
// function removeNote() {
// this.remove();
// }
newDivElem.append(newPElem);
noteContainer.append(newDivElem);
}
function clearInput() {
inputElem.value = "";
}
function addNote() {
let inputValue = inputElem.value;
createNote(inputValue);
inputElem.value = "";
inputElem.focus();
}
function addNoteWithKey(event) {
if (event.keyCode == 13) {
addNote();
}
}
colorBox.forEach(function (item) {
item.addEventListener("click", function () {
let bgColor = this.style.backgroundColor;
inputElem.style.backgroundColor = bgColor;
inputElem.focus();
});
});
//remove note by clicking in them:
noteContainer.addEventListener("click", function (event) {
if (event.target.tagName === "P") {
event.target.parentElement.remove();
}
});
</script>
</body>
</html>