From d1007bb645d6ed79b0d1a1af25e9fcc5e780b84e Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 10 Dec 2017 14:19:35 +1300 Subject: [PATCH] skip redirect when searching (if javascript is available) --- ArchiveState.go | 2 +- static/archive.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ArchiveState.go b/ArchiveState.go index 7d8c364..248aa67 100644 --- a/ArchiveState.go +++ b/ArchiveState.go @@ -317,7 +317,7 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { -
+ diff --git a/static/archive.js b/static/archive.js index 5c5e9b0..931f751 100755 --- a/static/archive.js +++ b/static/archive.js @@ -97,10 +97,29 @@ function onLoad() { highlightLine( parseInt(document.location.hash.substr(6), 10) ); } - // + // 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);