-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-lego.js
More file actions
164 lines (144 loc) · 4.14 KB
/
notes-lego.js
File metadata and controls
164 lines (144 loc) · 4.14 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
/**
* NOTES CONTAINER (Simple TODOs)
* Bottom-right container with a lightweight notes/TODO list
*/
let isNotesInitialized = false;
let notes = [];
function loadNotes() {
try {
const raw = localStorage.getItem('horus.notes');
notes = raw ? JSON.parse(raw) : [];
} catch (_) {
notes = [];
}
}
function saveNotes() {
try {
localStorage.setItem('horus.notes', JSON.stringify(notes));
} catch (_) {}
}
function renderNotesList() {
const list = document.getElementById('notes-list');
if (!list) return;
list.innerHTML = '';
notes.forEach((n, idx) => {
const item = document.createElement('div');
item.className = 'note-item';
item.innerHTML = `
<label class="note-check">
<input type="checkbox" ${n.done ? 'checked' : ''} data-idx="${idx}">
<span class="note-text ${n.done ? 'done' : ''}">${n.text}</span>
</label>
<button class="toolbar-btn note-del" data-idx="${idx}" title="Delete">✕</button>
`;
list.appendChild(item);
});
// Bind events
list.querySelectorAll('input[type="checkbox"]').forEach(cb => {
cb.addEventListener('change', (e) => {
const i = parseInt(e.target.getAttribute('data-idx'), 10);
if (!isNaN(i)) {
notes[i].done = !!e.target.checked;
saveNotes();
renderNotesList();
}
});
});
list.querySelectorAll('.note-del').forEach(btn => {
btn.addEventListener('click', (e) => {
const i = parseInt(e.currentTarget.getAttribute('data-idx'), 10);
if (!isNaN(i)) {
notes.splice(i, 1);
saveNotes();
renderNotesList();
}
});
});
}
function addNote(text) {
const t = (text || '').trim();
if (!t) return;
notes.unshift({ text: t, done: false, ts: Date.now() });
saveNotes();
renderNotesList();
}
function clearCompletedNotes() {
notes = notes.filter(n => !n.done);
saveNotes();
renderNotesList();
}
function initNotesContainer() {
if (isNotesInitialized) {
console.log('NOTES: Already initialized, just showing');
showNotes();
return;
}
console.log('NOTES: Initializing container...');
// Find the bottom-right container
const container = document.querySelector('.lego-container[data-position="bottom-right"]');
if (!container) {
console.error('NOTES: Container not found');
return;
}
// Load existing
loadNotes();
container.innerHTML = `
<div class="notes-wrapper">
<div class="panel-header">
<div style="display:flex;justify-content:space-between;align-items:center;">
<span>NOTES / TODO</span>
<div style="display:flex;gap:6px;">
<button class="toolbar-btn" id="notes-clear-done" title="Clear completed">Clear Done</button>
</div>
</div>
</div>
<div class="notes-content">
<div class="notes-input-row">
<input type="text" id="notes-input" placeholder="Add a note..." autocomplete="off" spellcheck="false">
<button class="toolbar-btn" id="notes-add">Add</button>
</div>
<div class="notes-list" id="notes-list"></div>
</div>
</div>
`;
// Bind controls
document.getElementById('notes-add').addEventListener('click', function() {
const inp = document.getElementById('notes-input');
addNote(inp.value);
inp.value = '';
inp.focus();
});
document.getElementById('notes-input').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addNote(e.target.value);
e.target.value = '';
}
});
document.getElementById('notes-clear-done').addEventListener('click', function() {
clearCompletedNotes();
});
renderNotesList();
isNotesInitialized = true;
console.log('NOTES: Initialized successfully');
}
function showNotes() {
if (!isNotesInitialized) {
initNotesContainer();
return;
}
console.log('NOTES: Showing container');
}
function hideNotes() {
console.log('NOTES: Hiding container');
}
// Export
if (typeof window !== 'undefined') {
window.NotesContainer = {
init: initNotesContainer,
show: showNotes,
hide: hideNotes,
add: addNote,
clearCompleted: clearCompletedNotes,
isInitialized: () => isNotesInitialized
};
}