skip redirect when searching (if javascript is available)

This commit is contained in:
mappu 2017-12-10 14:19:35 +13:00
parent 35b9973a4a
commit d1007bb645
2 changed files with 21 additions and 2 deletions

View File

@ -317,7 +317,7 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
</span> </span>
<span class="area-search"> <span class="area-search">
<form method="GET"> <form method="GET" id="search-form">
<input type="hidden" name="h" value="` + html.EscapeString(this.logBestSlug) + `"> <input type="hidden" name="h" value="` + html.EscapeString(this.logBestSlug) + `">
<input type="text" id="searchbox" name="q" value="` + html.EscapeString(this.query) + `" placeholder="Search..." accesskey="m" title="Search (Alt+M)"> <input type="text" id="searchbox" name="q" value="` + html.EscapeString(this.query) + `" placeholder="Search..." accesskey="m" title="Search (Alt+M)">
<input type="submit" value="&raquo;"> <input type="submit" value="&raquo;">

View File

@ -101,6 +101,25 @@ function onLoad() {
fontSize(0); fontSize(0);
//
var $form = document.getElementById("search-form");
$form.addEventListener("submit", function(ev) {
var query = $form.elements["q"].value;
if (query.length === 0) {
alert("No search text entered");
ev.preventDefault();
return false;
}
var prefix = ($form.elements["rx"].checked ? "/rx/" : "/search/");
window.location.hash = "";
window.location.pathname = "/" + $form.elements["h"].value + prefix + encodeURIComponent(query);
ev.preventDefault();
return false;
});
} }
window.addEventListener('load', onLoad); window.addEventListener('load', onLoad);