#12 Registered Shift + F for global search

This commit is contained in:
Serraniel 2020-07-29 13:51:11 +02:00
parent cae43ec998
commit 5230daaf17
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

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