-
Notifications
You must be signed in to change notification settings - Fork 0
/
sticky.js
143 lines (118 loc) · 5.53 KB
/
sticky.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
document.addEventListener('DOMContentLoaded', function() {
const newModel = document.getElementById("newModel");
const plus = document.getElementById("plus");
const closeBtn = document.getElementById("closeButton");
const notePreview = document.getElementById("notePreview");
const noteMenu = document.getElementById("noteMenu");
const preview = document.getElementById("preview");
const noteeMenu = document.getElementById("noteeMenu");
const submitNote1 = document.getElementById("submitNote")
const submitNote = document.getElementById("submitNote1");
const savedNotesContainer = document.getElementById("savedNotesContainer");
const colorBtn = document.querySelectorAll(".color-option");
let newNote = null;
plus.addEventListener('click', () => {
// Resetting everything when the plus button is clicked
newModel.style.display = "flex";
inputTitle.value = "";
inputContent.value = "";
notePreview.style.backgroundColor = getComputedStyle(colorBtn[0]).backgroundColor;
preview.innerHTML = ''; // Clear previous preview content
preview.style.display = "none"; // Hide the preview
newNote = null; // Reset newNote
});
closeBtn.addEventListener('click', () => {
newModel.style.display = "none";
});
if (colorBtn.length > 0) {
notePreview.style.backgroundColor = getComputedStyle(colorBtn[0]).backgroundColor;
}
colorBtn.forEach(child => {
child.addEventListener('click', () => {
notePreview.style.backgroundColor = getComputedStyle(child).backgroundColor;
});
});
noteMenu.addEventListener('click', () => {
const title = document.getElementById("inputTitle").value;
const content = document.getElementById("inputContent").value;
const noteColor = getComputedStyle(notePreview).backgroundColor;
// Creating the new note element
newNote = document.createElement('div');
newNote.className = 'note';
newNote.style.backgroundColor = noteColor;
newNote.innerHTML = `
<h3>${title}</h3>
<p>${content}</p>
`;
newNote.style.border = "2px solid white"
// Clearing any existing preview content and adding the new note
preview.innerHTML = '';
preview.appendChild(newNote);
// Ensure the preview buttons are also added back
preview.appendChild(noteeMenu.parentElement);
preview.style.display = "flex"; // Show the preview
newModel.style.display = "none"; // Hide the form
});
noteeMenu.addEventListener('click', () => {
// When "Back?" is clicked, go back to the note form
preview.style.display = "none";
newModel.style.display = "flex";
});
// submitnote.addEventListener('click', () => {
// newNote.style.border = "none"
// if (newNote) {
// const savedNote = newNote.cloneNode(true); // Clone the previewed note
// savedNotesContainer.appendChild(savedNote);
// newNote = null; // Reset newNote after saving
// preview.innerHTML = ''; // Clear the preview after submission
// preview.style.display = "none"; // Hide the preview
// } else {
// console.log("No note to submit.");
// }
// });
submitNote.addEventListener('click', () => {
newNote.style.border = "none"
if (newNote) {
const savedNote = newNote.cloneNode(true); // Clone the previewed note
savedNotesContainer.appendChild(savedNote);
newNote = null; // Reset newNote after saving
preview.innerHTML = ''; // Clear the preview after submission
preview.style.display = "none"; // Hide the preview
} else {
console.log("No note to submit.");
}
});
// function submitNoteHandler() {
// if (newNote) {
// newNote.style.border = "none"; // Remove border before saving
// const savedNote = newNote.cloneNode(true); // Clone the previewed note
// savedNotesContainer.appendChild(savedNote);
// newNote = null; // Reset newNote after saving
// preview.innerHTML = ''; // Clear the preview after submission
// preview.style.display = "none"; // Hide the preview
// } else {
// console.log("No note to submit.");
// }
// }
// submitNote1.addEventListener('click', submitNoteHandler);
// submitNote.addEventListener('click', submitNoteHandler);
submitNote1.addEventListener('click', () => {
const title = document.getElementById("inputTitle").value;
const content = document.getElementById("inputContent").value;
const noteColor = getComputedStyle(notePreview).backgroundColor;
// Creating the new note element
const newNoteForSave = document.createElement('div');
newNoteForSave.className = 'note';
newNoteForSave.style.backgroundColor = noteColor;
newNoteForSave.innerHTML = `
<h3>${title}</h3>
<p>${content}</p>
`;
newNoteForSave.style.border = "none";
savedNotesContainer.appendChild(newNoteForSave); // Save the note directly
// Reset the form and close it
inputTitle.value = "";
inputContent.value = "";
newModel.style.display = "none";
});
});