veza/apps/web/desy/legacy/js/ui/search.js
2026-01-22 17:23:11 +01:00

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();
}
});
}
}