Feature/#12 search input with hotkey #15

Merged
Serraniel merged 10 commits from feature/#12-search-input-with-hotkey into develop 2020-07-29 14:01:12 +02:00
Showing only changes of commit 5230daaf17 - Show all commits

View file

@ -1,3 +1,5 @@
const quickSearchID = 'ea-quickSearch';
runAfterLoad(() => {
initSearch();
}, ".*");
@ -13,7 +15,9 @@ function initSearch() {
quickSearchElement.type = 'text';
quickSearchElement.classList.add('ng-pristine', 'ng-valid', 'ng-empty', 'ng-touched');
quickSearchElement.placeholder = 'Quick Search (Shift + F)';
quickSearchElement.addEventListener('keydown', event => handleQuickSearch(event, quickSearchElement));
quickSearchElement.id = quickSearchID;
// register Enter keybinding
quickSearchElement.addEventListener('keypress', event => handleQuickSearch(event));
entry.appendChild(quickSearchElement);
@ -24,14 +28,26 @@ function initSearch() {
let menu = document.getElementById('materialize-menu-dropdown');
menu.insertAdjacentElement('beforeend', entry);
// register focus hotkey
document.addEventListener('keypress', event => handleSearchForShiftF(event));
}
function handleQuickSearch(event, quickSearchElement) {
function handleQuickSearch(event) {
if (event.key === 'Enter') {
let url = new URL(window.location.origin)
url.pathname = '/search';
url.searchParams.append('q', quickSearchElement.value);
url.searchParams.append('q', document.getElementById(quickSearchID).value);
window.location.href = url.href;
}
}
function handleSearchForShiftF(event) {
if (isShiftPressed) {
if (event.key === 'F') {
event.preventDefault();
document.getElementById(quickSearchID).focus();
}
}
}