-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSticky Notes by Me.html
More file actions
125 lines (100 loc) · 3.58 KB
/
Sticky Notes by Me.html
File metadata and controls
125 lines (100 loc) · 3.58 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sticky Notes</title>
<style>@import url('https://fonts.googleapis.com/css2?family=Aclonica&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #7158e2;
}
#container {
display: grid;
grid-template-columns: repeat(auto-fill,200px);
gap: 24px;
padding: 24px;
}
.sticky {
height: 200px;
padding: 16px;
border: none;
outline: none;
resize: none;
box-shadow: rgba(0, 0, 0, 0.3) 0px 19px 38px, rgba(0, 0, 0, 0.22) 0px 15px 12px;
}
.btn-add {
height: 200px;
border: none;
outline: none;
color: #fff;
font-size: 20px;
background-color: #c56cf0;
cursor: pointer;
}
.btn-add:hover{
background-color: #cd84f1;
border-radius: 5px;
}</style>
</head>
<body>
<div id="container">
<button class="btn-add">Add Note</button>
</div>
<script>const containerElement=document.getElementById("container");
const btnAdd=document.getElementsByClassName("btn-add")[0];
function getAppStorage(){
return JSON.parse(localStorage.getItem('rithish-app')||"[]");
}
getAppStorage().forEach(element => {
const textElement=createTextElement(element.id,element.content);
containerElement.insertBefore(textElement,btnAdd);
});
function createTextElement(id,content){
const textElement=document.createElement('textarea');
textElement.classList.add('sticky');
textElement.value=content;
textElement.placeholder='Enter Your Notes';
textElement.addEventListener("change",()=>{
updateNote(id,textElement.value)
})
textElement.addEventListener("dblclick",()=>{
const check=confirm("Are You to Sure Delete ?");
if(check){
deleteNotes(id,element);
}
});
return textElement;
}
function addSticky(){
const notes=getAppStorage();
const noteObject={
id:Math.floor(Math.random()*100000),
content:""
}
const textElement = createTextElement(noteObject.id,noteObject.content);
containerElement.insertBefore(textElement,btnAdd);
notes.push(noteObject);
saveNotes(notes);
}
btnAdd.addEventListener('click',()=>addSticky());
function saveNotes(notes){
localStorage.setItem("rithish-app",JSON.stringify(notes));
}
function updateNote(id,content){
const notes=getAppStorage();
const updateElement=notes.filter((note)=>note.id==id)[0];
updateElement.content=content;
saveNotes(notes);
}
function deleteNotes(id,content){
const notes=getAppStorage().filter((note)=>note.id!=id);
saveNotes(notes);
containerElement.removeChild(textElement);
}</script>
</body>
</html>