()
| 484 | } |
| 485 | |
| 486 | function initSearch() { |
| 487 | function clearSearch({ focus = true } = {}) { |
| 488 | if (!searchInput) return; |
| 489 | searchInput.value = ''; |
| 490 | renderSection(currentSectionId, { updateUrl: true, clearSearch: false, scroll: false }); |
| 491 | clearSearchBtn?.classList.remove('visible'); |
| 492 | setResultStatus('', false); |
| 493 | if (focus) searchInput.focus(); |
| 494 | } |
| 495 | |
| 496 | searchInput?.addEventListener('input', (event) => { |
| 497 | renderSearch(event.target.value || '', { updateUrl: true }); |
| 498 | }); |
| 499 | |
| 500 | clearSearchBtn?.addEventListener('click', () => clearSearch()); |
| 501 | resultClearBtn?.addEventListener('click', () => clearSearch()); |
| 502 | |
| 503 | contentContainer?.addEventListener('click', (event) => { |
| 504 | const target = event.target; |
| 505 | if (!(target instanceof Element)) return; |
| 506 | const action = target.closest('[data-empty-action]')?.getAttribute('data-empty-action'); |
| 507 | if (!action) return; |
| 508 | |
| 509 | if (action === 'featured') { |
| 510 | if (searchInput) searchInput.value = ''; |
| 511 | renderSection('featured', { updateUrl: true, clearSearch: false, scroll: true }); |
| 512 | clearSearchBtn?.classList.remove('visible'); |
| 513 | setResultStatus('', false); |
| 514 | } else if (action === 'clear') { |
| 515 | clearSearch(); |
| 516 | } |
| 517 | }); |
| 518 | } |
| 519 | |
| 520 | async function copyUrl(url) { |
| 521 | const clipboard = window.navigator?.clipboard; |
nothing calls this directly
no test coverage detected