-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnhancedNotesApp.html
More file actions
116 lines (100 loc) · 4.78 KB
/
EnhancedNotesApp.html
File metadata and controls
116 lines (100 loc) · 4.78 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Notes App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5" style="max-width: 800px;">
<header class="text-center mb-4">
<h1 class="text-primary"><img src="note.png" height="80px"/>Notes App</h1>
</header>
<div class="card p-3 mb-4">
<input type="text" id="addTitle" class="form-control mb-2" placeholder="Note Title">
<textarea id="addText" class="form-control mb-2" placeholder="Take a note..."></textarea>
<button id="addNote" class="btn btn-primary">Add Note</button>
</div>
<div id="notes" class="row g-3"></div>
</div>
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">Edit Note</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input type="text" id="editTitle" class="form-control mb-2" placeholder="Note Title">
<textarea id="editText" class="form-control" placeholder="Edit your note..."></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="saveEdit">Save</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
const addTitle = document.getElementById('addTitle');
const addText = document.getElementById('addText');
const addNoteButton = document.getElementById('addNote');
const notesDiv = document.getElementById('notes');
let editIndex = -1;
showNotes();
addNoteButton.addEventListener('click', () => {
const title = addTitle.value.trim();
const text = addText.value.trim();
if (!text) {
alert('Please add some text for the note.');
return;
}
const notes = JSON.parse(localStorage.getItem('notes') || '[]');
notes.push({ title: title || 'Untitled', text });
localStorage.setItem('notes', JSON.stringify(notes));
addTitle.value = '';
addText.value = '';
showNotes();
});
function showNotes() {
const notes = JSON.parse(localStorage.getItem('notes') || '[]');
notesDiv.innerHTML = notes.map((note, index) => `
<div class="col-md-4">
<div class="card p-3">
<h5 class="text-primary">${note.title}</h5>
<p>${note.text.substring(0, 50)}...</p>
<div class="d-flex gap-2">
<button class="btn btn-sm btn-warning" onclick="editNote(${index})" data-bs-toggle="modal" data-bs-target="#editModal">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteNote(${index})">🗑️</button>
</div>
</div>
</div>
`).join('');
}
function deleteNote(index) {
const notes = JSON.parse(localStorage.getItem('notes') || '[]');
notes.splice(index, 1);
localStorage.setItem('notes', JSON.stringify(notes));
showNotes();
}
function editNote(index) {
const notes = JSON.parse(localStorage.getItem('notes') || '[]');
editIndex = index;
document.getElementById('editTitle').value = notes[index].title;
document.getElementById('editText').value = notes[index].text;
}
document.getElementById('saveEdit').addEventListener('click', () => {
const notes = JSON.parse(localStorage.getItem('notes') || '[]');
notes[editIndex] = {
title: document.getElementById('editTitle').value,
text: document.getElementById('editText').value
};
localStorage.setItem('notes', JSON.stringify(notes));
showNotes();
bootstrap.Modal.getInstance(document.getElementById('editModal')).hide();
});
</script>
</body>
</html>