|
1 | 1 | (function () { |
2 | 2 | const notesInput = document.querySelector('[data-notes-input]'); |
3 | | - const entryEl = document.querySelector('[data-entry-text]'); |
| 3 | + const currentEntryEl = document.querySelector('[data-current-text]'); |
| 4 | + const previewEntryEl = document.querySelector('[data-preview-text]'); |
| 5 | + const previewCard = document.querySelector('[data-preview-card]'); |
4 | 6 | const counterEl = document.querySelector('[data-counter]'); |
5 | 7 | const prevButton = document.querySelector('[data-prev]'); |
6 | 8 | const nextButton = document.querySelector('[data-next]'); |
|
11 | 13 |
|
12 | 14 | if ( |
13 | 15 | !notesInput || |
14 | | - !entryEl || |
| 16 | + !currentEntryEl || |
| 17 | + !previewEntryEl || |
| 18 | + !previewCard || |
15 | 19 | !counterEl || |
16 | 20 | !prevButton || |
17 | 21 | !nextButton || |
|
30 | 34 | "I told my computer I needed a break, and it said 'No problem — I'll go to sleep.'", |
31 | 35 | 'Why did the scarecrow get a promotion? He was outstanding in his field.' |
32 | 36 | ].join('\n\n'); |
| 37 | + const PREVIEW_PLACEHOLDER = 'Add another note to preview the upcoming card.'; |
33 | 38 |
|
34 | 39 | let entries = []; |
35 | 40 | let deckOrder = []; |
|
177 | 182 |
|
178 | 183 | function renderEmptyState() { |
179 | 184 | counterEl.textContent = '0 of 0'; |
180 | | - entryEl.textContent = 'No notes yet. Add entries below to start reviewing.'; |
181 | | - entryEl.classList.add('is-empty'); |
| 185 | + currentEntryEl.textContent = 'No notes yet. Add entries below to start reviewing.'; |
| 186 | + currentEntryEl.classList.add('is-empty'); |
| 187 | + previewEntryEl.textContent = PREVIEW_PLACEHOLDER; |
| 188 | + previewEntryEl.classList.add('is-empty'); |
| 189 | + previewCard.setAttribute('aria-hidden', 'true'); |
182 | 190 | prevButton.disabled = true; |
183 | 191 | nextButton.disabled = true; |
184 | 192 | shuffleButton.disabled = true; |
|
200 | 208 | const currentEntryIndex = deckOrder[index]; |
201 | 209 | const current = entries[currentEntryIndex]; |
202 | 210 |
|
203 | | - entryEl.textContent = current; |
204 | | - entryEl.classList.remove('is-empty'); |
| 211 | + currentEntryEl.textContent = current; |
| 212 | + currentEntryEl.classList.remove('is-empty'); |
205 | 213 | counterEl.textContent = `${index + 1} of ${deckOrder.length}`; |
206 | 214 | const disableNav = deckOrder.length <= 1; |
207 | 215 | prevButton.disabled = disableNav; |
208 | 216 | nextButton.disabled = disableNav; |
209 | 217 | shuffleButton.disabled = deckOrder.length <= 1; |
| 218 | + |
| 219 | + if (deckOrder.length > 1) { |
| 220 | + const previewEntryIndex = deckOrder[(index + 1) % deckOrder.length]; |
| 221 | + const preview = entries[previewEntryIndex]; |
| 222 | + previewEntryEl.textContent = preview; |
| 223 | + previewEntryEl.classList.remove('is-empty'); |
| 224 | + previewCard.removeAttribute('aria-hidden'); |
| 225 | + } else { |
| 226 | + previewEntryEl.textContent = PREVIEW_PLACEHOLDER; |
| 227 | + previewEntryEl.classList.add('is-empty'); |
| 228 | + previewCard.setAttribute('aria-hidden', 'true'); |
| 229 | + } |
210 | 230 | } |
211 | 231 |
|
212 | 232 | function showNext() { |
|
0 commit comments