|
1 | 1 | (function () { |
2 | 2 | const notesInput = document.querySelector('[data-notes-input]'); |
3 | 3 | const entryEl = document.querySelector('[data-entry-text]'); |
4 | | - const placeholderEl = document.querySelector('[data-placeholder]'); |
5 | 4 | const counterEl = document.querySelector('[data-counter]'); |
6 | 5 | const prevButton = document.querySelector('[data-prev]'); |
7 | 6 | const nextButton = document.querySelector('[data-next]'); |
8 | | - const revealButton = document.querySelector('[data-reveal]'); |
9 | 7 | const shuffleButton = document.querySelector('[data-shuffle]'); |
10 | 8 | const saveButton = document.querySelector('[data-save]'); |
11 | 9 | const resetButton = document.querySelector('[data-reset]'); |
|
14 | 12 | if ( |
15 | 13 | !notesInput || |
16 | 14 | !entryEl || |
17 | | - !placeholderEl || |
18 | 15 | !counterEl || |
19 | 16 | !prevButton || |
20 | 17 | !nextButton || |
21 | | - !revealButton || |
22 | 18 | !shuffleButton || |
23 | 19 | !saveButton || |
24 | 20 | !resetButton || |
|
37 | 33 | let entries = []; |
38 | 34 | let deck = []; |
39 | 35 | let index = 0; |
40 | | - let isVisible = false; |
41 | 36 |
|
42 | 37 | function setStatus(message) { |
43 | 38 | statusEl.textContent = message; |
|
89 | 84 | } |
90 | 85 | } |
91 | 86 |
|
92 | | - function setEntryVisible(visible) { |
93 | | - isVisible = visible; |
94 | | - entryEl.classList.toggle('is-visible', visible); |
95 | | - entryEl.setAttribute('aria-hidden', visible ? 'false' : 'true'); |
96 | | - placeholderEl.hidden = visible; |
97 | | - revealButton.setAttribute('aria-pressed', visible ? 'true' : 'false'); |
98 | | - revealButton.textContent = visible ? 'Hide note' : 'Reveal note'; |
99 | | - } |
100 | | - |
101 | 87 | function renderEmptyState() { |
102 | 88 | counterEl.textContent = '0 of 0'; |
103 | | - isVisible = false; |
104 | | - entryEl.textContent = ''; |
105 | | - entryEl.classList.remove('is-visible'); |
106 | | - entryEl.setAttribute('aria-hidden', 'true'); |
107 | | - placeholderEl.hidden = false; |
108 | | - placeholderEl.textContent = 'No notes yet. Add entries below to start reviewing.'; |
109 | | - revealButton.disabled = true; |
110 | | - revealButton.setAttribute('aria-pressed', 'false'); |
111 | | - revealButton.textContent = 'Reveal note'; |
| 89 | + entryEl.textContent = 'No notes yet. Add entries below to start reviewing.'; |
| 90 | + entryEl.classList.add('is-empty'); |
112 | 91 | prevButton.disabled = true; |
113 | 92 | nextButton.disabled = true; |
114 | 93 | shuffleButton.disabled = true; |
|
124 | 103 | const current = deck[index]; |
125 | 104 |
|
126 | 105 | entryEl.textContent = current; |
| 106 | + entryEl.classList.remove('is-empty'); |
127 | 107 | counterEl.textContent = `${index + 1} of ${deck.length}`; |
128 | | - placeholderEl.textContent = 'Ready when you are. Press “Reveal note” or tap space to check your recall.'; |
129 | | - |
130 | | - revealButton.disabled = false; |
131 | 108 | const disableNav = deck.length <= 1; |
132 | 109 | prevButton.disabled = disableNav; |
133 | 110 | nextButton.disabled = disableNav; |
134 | 111 | shuffleButton.disabled = deck.length <= 1; |
135 | | - |
136 | | - setEntryVisible(false); |
137 | 112 | } |
138 | 113 |
|
139 | 114 | function showNext() { |
|
154 | 129 | render(); |
155 | 130 | } |
156 | 131 |
|
157 | | - function toggleEntry() { |
158 | | - if (!entries.length) { |
159 | | - return; |
160 | | - } |
161 | | - setEntryVisible(!isVisible); |
162 | | - } |
163 | | - |
164 | 132 | function reshuffleDeck() { |
165 | 133 | if (entries.length <= 1) { |
166 | 134 | return; |
|
203 | 171 |
|
204 | 172 | prevButton.addEventListener('click', showPrev); |
205 | 173 | nextButton.addEventListener('click', showNext); |
206 | | - revealButton.addEventListener('click', toggleEntry); |
207 | 174 | shuffleButton.addEventListener('click', reshuffleDeck); |
208 | 175 | saveButton.addEventListener('click', handleSave); |
209 | 176 | resetButton.addEventListener('click', handleReset); |
|
219 | 186 | } else if (event.key === 'ArrowLeft') { |
220 | 187 | event.preventDefault(); |
221 | 188 | showPrev(); |
222 | | - } else if (event.key === ' ' || event.key === 'Spacebar') { |
223 | | - const active = document.activeElement; |
224 | | - if ( |
225 | | - active && |
226 | | - (active.tagName === 'BUTTON' || |
227 | | - active.tagName === 'TEXTAREA' || |
228 | | - active.tagName === 'INPUT' || |
229 | | - active.tagName === 'A' || |
230 | | - active.tagName === 'SUMMARY' || |
231 | | - active.tagName === 'SELECT') |
232 | | - ) { |
233 | | - return; |
234 | | - } |
235 | | - event.preventDefault(); |
236 | | - toggleEntry(); |
237 | 189 | } |
238 | 190 | }); |
239 | 191 |
|
|
0 commit comments