Use paige prefix in search code
This commit is contained in:
@@ -45,28 +45,28 @@
|
|||||||
<article id="paige-results" style="display: none"></article>
|
<article id="paige-results" style="display: none"></article>
|
||||||
<script crossorigin="anonymous" defer integrity="sha384-1LalyFI+BycKouEClZE5CoFnlLr+Kx8Wslc45o5NATVo+c2mEh02i8HNaaT7XOdQ" referrerpolicy="no-referrer" src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.7.31/dist/flexsearch.bundle.js"></script>
|
<script crossorigin="anonymous" defer integrity="sha384-1LalyFI+BycKouEClZE5CoFnlLr+Kx8Wslc45o5NATVo+c2mEh02i8HNaaT7XOdQ" referrerpolicy="no-referrer" src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.7.31/dist/flexsearch.bundle.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var errorElement = document.getElementById("paige-error");
|
var paigeErrorElement = document.getElementById("paige-error");
|
||||||
var nothingElement = document.getElementById("paige-nothing");
|
var paigeNothingElement = document.getElementById("paige-nothing");
|
||||||
var queryElement = document.getElementById("query");
|
var paigeQueryElement = document.getElementById("query");
|
||||||
var searchingElement = document.getElementById("paige-searching")
|
var paigeSearchingElement = document.getElementById("paige-searching")
|
||||||
var somethingElement = document.getElementById("paige-something");
|
var paigeSomethingElement = document.getElementById("paige-something");
|
||||||
var resultsElement = document.getElementById("paige-results");
|
var paigeResultsElement = document.getElementById("paige-results");
|
||||||
|
|
||||||
if (queryElement !== null) {
|
if (paigeQueryElement !== null) {
|
||||||
var queryText = decodeURIComponent((location.search.split("q=")[1] || "").split("&")[0]).replace(/\+/g, " ");
|
var queryText = decodeURIComponent((location.search.split("q=")[1] || "").split("&")[0]).replace(/\+/g, " ");
|
||||||
if (queryText) {
|
if (queryText) {
|
||||||
queryElement.value = queryText;
|
paigeQueryElement.value = queryText;
|
||||||
search(queryText);
|
paigeSearch(queryText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(queryText) {
|
function paigeSearch(queryText) {
|
||||||
show(searchingElement);
|
paigeShow(paigeSearchingElement);
|
||||||
fetch("/index.json").then(function (response) {
|
fetch("/index.json").then(function (response) {
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.log("Cannot load /index.json", response);
|
console.log("Cannot load /index.json", response);
|
||||||
hide(searchingElement);
|
paigeHide(paigeSearchingElement);
|
||||||
show(errorElement);
|
paigeShow(paigeErrorElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response.json().then(function (pages) {
|
response.json().then(function (pages) {
|
||||||
@@ -82,7 +82,7 @@ function search(queryText) {
|
|||||||
pathPage[page.link] = page;
|
pathPage[page.link] = page;
|
||||||
});
|
});
|
||||||
var results = index.search(queryText, {limit: 50});
|
var results = index.search(queryText, {limit: 50});
|
||||||
hide(searchingElement);
|
paigeHide(paigeSearchingElement);
|
||||||
var shown = false;
|
var shown = false;
|
||||||
var done = {};
|
var done = {};
|
||||||
results.forEach(function (result) {
|
results.forEach(function (result) {
|
||||||
@@ -92,8 +92,8 @@ function search(queryText) {
|
|||||||
}
|
}
|
||||||
if (!shown) {
|
if (!shown) {
|
||||||
shown = true;
|
shown = true;
|
||||||
show(somethingElement);
|
paigeShow(paigeSomethingElement);
|
||||||
show(resultsElement);
|
paigeShow(paigeResultsElement);
|
||||||
}
|
}
|
||||||
done[path] = true;
|
done[path] = true;
|
||||||
var page = pathPage[path];
|
var page = pathPage[path];
|
||||||
@@ -107,11 +107,11 @@ function search(queryText) {
|
|||||||
result.appendChild(document.createElement("br"));
|
result.appendChild(document.createElement("br"));
|
||||||
result.innerHTML += page.description;
|
result.innerHTML += page.description;
|
||||||
}
|
}
|
||||||
resultsElement.appendChild(result);
|
paigeResultsElement.appendChild(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (!shown) {
|
if (!shown) {
|
||||||
show(nothingElement);
|
paigeShow(paigeNothingElement);
|
||||||
}
|
}
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
console.log("Cannot search /index.json", error);
|
console.log("Cannot search /index.json", error);
|
||||||
@@ -119,11 +119,11 @@ function search(queryText) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function hide(element) {
|
function paigeHide(element) {
|
||||||
element.style.display = "none";
|
element.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(element) {
|
function paigeShow(element) {
|
||||||
element.style.display = "block";
|
element.style.display = "block";
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user