#12 Base search input

This commit is contained in:
Serraniel 2020-07-29 13:26:59 +02:00
parent ce23bd835a
commit c8046070c2
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -0,0 +1,33 @@
registerScript(node => {
initSearch();
}, ".*");
function initSearch() {
let menu = document.getElementById('materialize-menu-dropdown');
let entry = document.createElement('li');
entry.setAttribute('ng-repeat', 'item in navbar');
entry.setAttribute('ng-class', '{\'anime-indicator\': item[\'@attributes\'].title==\'Anime\'}');
let quickSearchElement = document.createElement('input');
quickSearchElement.setAttribute('aria-label', 'Quick Search Input');
quickSearchElement.setAttribute('ng-model-options', '{debounce: 500}');
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));
entry.appendChild(quickSearchElement);
menu.insertAdjacentElement('beforeend', entry);
}
function handleQuickSearch(event, quickSearchElement) {
if (event.key === 'Enter') {
let url = new URL(window.location.origin)
url.pathname = '/search';
url.searchParams.append('q', quickSearchElement.value);
window.location.href = url.href;
}
}