mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2025-07-20 01:42:36 +02:00
act only if results are available
This commit is contained in:
@@ -2,6 +2,7 @@ var fuse; // holds our search engine
|
|||||||
var resList = document.getElementById('searchResults');
|
var resList = document.getElementById('searchResults');
|
||||||
var sInput = document.getElementById('searchInput');
|
var sInput = document.getElementById('searchInput');
|
||||||
var first, last = null
|
var first, last = null
|
||||||
|
var resultsAvailable = false;
|
||||||
|
|
||||||
// load our search index, only executed onload
|
// load our search index, only executed onload
|
||||||
function loadSearch() {
|
function loadSearch() {
|
||||||
@@ -42,7 +43,7 @@ function loadSearch() {
|
|||||||
// kb bindings
|
// kb bindings
|
||||||
document.onkeydown = function (e) {
|
document.onkeydown = function (e) {
|
||||||
let key = e.key;
|
let key = e.key;
|
||||||
if (key === "ArrowDown") {
|
if (key === "ArrowDown" && resultsAvailable) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (document.activeElement == sInput) {
|
if (document.activeElement == sInput) {
|
||||||
resList.firstChild.lastChild.focus();
|
resList.firstChild.lastChild.focus();
|
||||||
@@ -50,7 +51,7 @@ document.onkeydown = function (e) {
|
|||||||
} else {
|
} else {
|
||||||
document.activeElement.parentElement.nextSibling.lastChild.focus();
|
document.activeElement.parentElement.nextSibling.lastChild.focus();
|
||||||
}
|
}
|
||||||
} else if (key === "ArrowUp") {
|
} else if (key === "ArrowUp" && resultsAvailable) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (document.activeElement == sInput) {
|
if (document.activeElement == sInput) {
|
||||||
} else if (document.activeElement.parentElement == first) {
|
} else if (document.activeElement.parentElement == first) {
|
||||||
@@ -77,10 +78,11 @@ document.getElementById("searchInput").onkeyup = function (e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("searchResults").innerHTML = resultSet;
|
document.getElementById("searchResults").innerHTML = resultSet;
|
||||||
|
resultsAvailable = true;
|
||||||
first = resList.firstChild;
|
first = resList.firstChild;
|
||||||
last = resList.lastChild;
|
last = resList.lastChild;
|
||||||
} else {
|
} else {
|
||||||
|
resultsAvailable = false;
|
||||||
document.getElementById("searchResults").innerHTML = '';
|
document.getElementById("searchResults").innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user