replace js state setting, with URL targets in select values ; remove "PCRE" from regex tooltip

This commit is contained in:
mappu 2017-12-10 12:50:11 +13:00
parent 7b9aece4d2
commit 8568c4bdc2
2 changed files with 52 additions and 63 deletions

View File

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"math" "math"
"net/http" "net/http"
"net/url"
"os" "os"
"regexp" "regexp"
"strings" "strings"
@ -199,28 +200,34 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
<span class="area-nav"> <span class="area-nav">
<form method="GET" id="frmHub"> <select onchange="window.location.pathname = this.value;">
<select name="h" id="selHub">
`)) `))
for i, h := range this.svr.cfg.Logs { for i, h := range this.svr.cfg.Logs {
slug, _ := this.svr.bestSlugFor(&this.svr.cfg.Logs[i]) slug, _ := this.svr.bestSlugFor(&this.svr.cfg.Logs[i])
current := (this.log == &this.svr.cfg.Logs[i]) current := (this.log == &this.svr.cfg.Logs[i])
w.Write([]byte(`<option value="` + html.EscapeString(slug) + `" ` + attr(current, "selected") + `>` + html.EscapeString(h.Description) + `</option>`)) targetUri := `/` + url.PathEscape(slug) + `/`
if len(this.query) > 0 {
if this.queryIsRegex {
targetUri += `rx/` + url.PathEscape(this.query)
} else {
targetUri += `search/` + url.PathEscape(this.query)
}
} else {
targetUri += fmt.Sprintf(`%d/%d`, h.LatestDate().Year, h.LatestDate().Month)
}
w.Write([]byte(`<option value="` + html.EscapeString(targetUri) + `" ` + attr(current, "selected") + `>` + html.EscapeString(h.Description) + `</option>`))
} }
w.Write([]byte(` w.Write([]byte(`
</select> </select>
</form>
`)) `))
if showPageURLs { if showPageURLs {
w.Write([]byte(` w.Write([]byte(`
<select onchange="window.location.pathname = this.value;">
<form method="GET">
<input type="hidden" name="h" value="` + html.EscapeString(this.logBestSlug) + `">
<select id="seldate" onchange="setYM(this);">
`)) `))
// Generate month dropdown options // Generate month dropdown options
@ -236,8 +243,18 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
lastY = ympair.Year lastY = ympair.Year
} }
w.Write([]byte(fmt.Sprintf(`<option value="%d-%d" %s>%s</option>`, ympair.Year, ympair.Month, attr(ympair.Equals(this.ym), "selected"), html.EscapeString(ympair.Month.String())))) targetUri := fmt.Sprintf(`/%s/%d/%d`, this.logBestSlug, ympair.Year, ympair.Month)
w.Write([]byte(fmt.Sprintf(`<option value="%s" %s>%s</option>`, html.EscapeString(targetUri), attr(ympair.Equals(this.ym), "selected"), html.EscapeString(ympair.Month.String()))))
} }
if lastY != -1 {
w.Write([]byte(`</optgroup>`))
}
w.Write([]byte(`
</select>
<div class="mini-separator layout-pushdown"></div>
`))
// //
@ -259,43 +276,33 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
nextMonthLink := fmt.Sprintf(`/%s/%d/%d`, this.logBestSlug, nextMonth.Year, nextMonth.Month) nextMonthLink := fmt.Sprintf(`/%s/%d/%d`, this.logBestSlug, nextMonth.Year, nextMonth.Month)
w.Write([]byte(` w.Write([]byte(`
</optgroup> <a style="display:none;" id="monthprev" accesskey="j" href="` + html.EscapeString(prevMonthLink) + `">
<a style="display:none;" id="monthnext" accesskey="k" href="` + html.EscapeString(nextMonthLink) + `">
</select> <a class="btn" href="` + pageBase + `/page-0">&laquo;</a>
<input type="hidden" name="y" id="f_y" value=""> <a class="btn" id="pgprev" accesskey="h" title="Previous page (Alt+H)" href="` + pageBase + `/page-` + fmt.Sprintf("%d", previousPage) + `">&lsaquo;</a>
<input type="hidden" name="m" id="f_m" value=""> ` + fmt.Sprintf("%d", this.page) + `
<input type="hidden" name="p" value="0" > <a class="btn" id="pgnext" accesskey="l" title="Next page (Alt+L)" href="` + pageBase + `/page-` + fmt.Sprintf("%d", nextPage) + `">&rsaquo;</a>
</form> <a class="btn" href="` + pageBase + `">&raquo;</a>
<div class="mini-separator layout-pushdown"></div>
<a style="display:none;" id="monthprev" accesskey="j" href="` + html.EscapeString(prevMonthLink) + `">
<a style="display:none;" id="monthnext" accesskey="k" href="` + html.EscapeString(nextMonthLink) + `">
<a class="btn" href="` + pageBase + `/page-0">&laquo;</a>
<a class="btn" id="pgprev" accesskey="h" title="Previous page (Alt+H)" href="` + pageBase + `/page-` + fmt.Sprintf("%d", previousPage) + `">&lsaquo;</a>
` + fmt.Sprintf("%d", this.page) + `
<a class="btn" id="pgnext" accesskey="l" title="Next page (Alt+L)" href="` + pageBase + `/page-` + fmt.Sprintf("%d", nextPage) + `">&rsaquo;</a>
<a class="btn" href="` + pageBase + `">&raquo;</a>
`)) `))
} }
w.Write([]byte(` w.Write([]byte(`
<div class="pad"></div> <div class="pad"></div>
</span> </span>
<span class="area-search"> <span class="area-search">
<form method="GET"> <form method="GET">
<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;">
<input type="checkbox" class="layout-pushdown" name="rx" value="1" title="PCRE Regular Expression" ` + attr(this.queryIsRegex, "checked") + `> <input type="checkbox" class="layout-pushdown" name="rx" value="1" title="Regular Expression" ` + attr(this.queryIsRegex, "checked") + `>
</form> </form>
</span> </span>
</div> </div>
<div class="layout-body" id="chatarea"> <div class="layout-body" id="chatarea">
`)) `))
// Header ends // Header ends

View File

@ -3,14 +3,8 @@
var alreadyLoaded = false; var alreadyLoaded = false;
var $chatArea = document.getElementById("chatarea"); var $chatArea = document.getElementById("chatarea");
var $selHub = document.getElementById("selHub");
var $frmHub = document.getElementById("frmHub");
var DEFAULT_FONT_SIZE = 12; var DEFAULT_FONT_SIZE = 12;
function urldesc(s) {
return decodeURIComponent(s.replace(/\+/g, " "));
}
function cookie_set(key, value) { function cookie_set(key, value) {
document.cookie = (key+"="+value+"; expires=Sat, 20 Sep 2059 09:05:12; path=/"); document.cookie = (key+"="+value+"; expires=Sat, 20 Sep 2059 09:05:12; path=/");
} }
@ -30,6 +24,10 @@ function cookie_get(key) {
} }
function highlight(str) { function highlight(str) {
var urldesc = function(s) {
return decodeURIComponent(s.replace(/\+/g, " "));
};
return str return str
.replace(/(\[\d\d\d\d-\d\d-\d\d\s\d\d\:\d\d\:\d\d\] )(\*.+)/g, "$1<span class=\"sys\">$2</span>") .replace(/(\[\d\d\d\d-\d\d-\d\d\s\d\d\:\d\d\:\d\d\] )(\*.+)/g, "$1<span class=\"sys\">$2</span>")
.replace( .replace(
@ -104,22 +102,6 @@ function onLoad() {
fontSize(0); fontSize(0);
//
$selHub.onchange = function() {
if ( /\/search\//.test(window.location.pathname) ) {
window.location.pathname = $selHub.value + "/search/" + encodeURIComponent( i('searchbox').value );
} else if ( /\/rx\//.test(window.location.pathname) ) {
window.location.pathname = $selHub.value + "/rx/" + encodeURIComponent( i('searchbox').value )
} else {
$frmHub.submit();
}
};
//
} }
window.addEventListener('load', onLoad); window.addEventListener('load', onLoad);