33 lines
992 B
JavaScript
33 lines
992 B
JavaScript
/* SEARCH MODAL LOGIC */
|
|
export function initSearch() {
|
|
const searchModal = document.getElementById('searchModal');
|
|
const searchInput = document.getElementById('searchInput');
|
|
|
|
function toggleSearch() {
|
|
if (!searchModal) return;
|
|
searchModal.classList.toggle('active');
|
|
if (searchModal.classList.contains('active')) {
|
|
if (searchInput) searchInput.focus();
|
|
}
|
|
}
|
|
|
|
// Keydown Events (Cmd+K / Esc)
|
|
document.addEventListener('keydown', (e) => {
|
|
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
|
|
e.preventDefault();
|
|
toggleSearch();
|
|
}
|
|
if (e.key === 'Escape' && searchModal && searchModal.classList.contains('active')) {
|
|
toggleSearch();
|
|
}
|
|
});
|
|
|
|
// Close on backdrop click
|
|
if (searchModal) {
|
|
searchModal.addEventListener('click', (e) => {
|
|
if (e.target === searchModal) {
|
|
toggleSearch();
|
|
}
|
|
});
|
|
}
|
|
}
|