Fix search
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2020-11-17 00:00:35 +01:00
parent 692a065f82
commit 31ff5555d8
2 changed files with 21 additions and 5 deletions

View File

@ -132,9 +132,21 @@ function showSearchResultsExtended(element, template, searchTool, query, input,
let $ul = el('ul',
_.map(results, (hit, i) => {
const li = el('li', [document.createTextNode(hit.item.label || hit.item.title)])
let div = el('div', []);
div.innerHTML = hit.text
const fragment = hit.text ? [div] : []
let children = [
document.createTextNode(hit.title || hit.item.label || hit.item.title),
...(fragment)
];
if (hit.ref) {
children = hit.ref ? [el('a', children)] : children;
children[0].setAttribute('href', '/edit/' + hit.ref)
}
const li = el('li', children)
if (selectedPos === i) li.classList.add('selected')
li.dataset['new_page'] = hit.item.title
li.dataset['new_page'] = hit.title || hit.item.title
return li
})
)

View File

@ -43,7 +43,7 @@ $(document).on('keydown', '#search-input', function (event) {
if (event.key === 'Enter') {
_.defer(() => {
let $a = $('#autocomplete li.selected > a');
$a[0].click()
if ($a.length) $a[0].click()
})
return true;
}
@ -54,12 +54,16 @@ $(document).on('keydown', '#search-input', function (event) {
if (event.key === 'ArrowDown') {
let x = $ac.find('li.selected').removeClass('selected').next('li').addClass('selected')
x[0].scrollIntoView({behavior: "smooth", block: "nearest"})
if (x.length) {
x[0].scrollIntoView({behavior: "smooth", block: "nearest"})
}
return false
}
if (event.key === 'ArrowUp') {
let x = $ac.find('li.selected').removeClass('selected').prev('li').addClass('selected')
x[0].scrollIntoView({behavior: "smooth", block: "nearest"})
if (x.length) {
x[0].scrollIntoView({behavior: "smooth", block: "nearest"})
}
return false
}