You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
function setQueryParam(s) {
|
|
let params = URLSearchParams(window.location.search)
|
|
params.set("q", s);
|
|
var newRelativePathQuery = window.location.pathname + '?' + params.toString();
|
|
history.pushState(null, '', newRelativePathQuery);
|
|
}
|
|
|
|
function searchTriggered() {
|
|
let searchbox = document.getElementById("searchbox");
|
|
let query = searchbox.value
|
|
searchFor(query)
|
|
setQueryParam(query)
|
|
passQueryToResultpage(query)
|
|
}
|
|
|
|
async function searchFor(query) {
|
|
var url = new URL(location.origin+"/api/search")
|
|
url.searchParams.append("q",query)
|
|
const res = await fetch(url)
|
|
let results = await res.json();
|
|
if (results == null){
|
|
console.error("No results.")
|
|
alert("No results found.")
|
|
}
|
|
passResultToResultpage(results)
|
|
}
|
|
|
|
function passResultToResultpage(results) {
|
|
let resultPageIframe = document.getElementById("resultPage");
|
|
resultPageIframe.contentWindow.postMessage({
|
|
type: "results",
|
|
results: JSON.stringify(results)
|
|
}, '*');
|
|
}
|
|
|
|
function passQueryToResultpage(query) {
|
|
let resultPageIframe = document.getElementById("resultPage");
|
|
resultPageIframe.contentWindow.postMessage({
|
|
type: "query",
|
|
query: query
|
|
}, '*');
|
|
}
|