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"
"math"
"net/http"
"net/url"
"os"
"regexp"
"strings"
@ -199,28 +200,34 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
<span class="area-nav">
<form method="GET" id="frmHub">
<select name="h" id="selHub">
<select onchange="window.location.pathname = this.value;">
`))
for i, h := range this.svr.cfg.Logs {
slug, _ := this.svr.bestSlugFor(&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(`
</select>
</form>
</select>
`))
if showPageURLs {
w.Write([]byte(`
<form method="GET">
<input type="hidden" name="h" value="` + html.EscapeString(this.logBestSlug) + `">
<select id="seldate" onchange="setYM(this);">
<select onchange="window.location.pathname = this.value;">
`))
// Generate month dropdown options
@ -236,8 +243,18 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
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)
w.Write([]byte(`
</optgroup>
</select>
<input type="hidden" name="y" id="f_y" value="">
<input type="hidden" name="m" id="f_m" value="">
<input type="hidden" name="p" value="0" >
</form>
<a style="display:none;" id="monthprev" accesskey="j" href="` + html.EscapeString(prevMonthLink) + `">
<a style="display:none;" id="monthnext" accesskey="k" href="` + html.EscapeString(nextMonthLink) + `">
<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>
<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(`
<div class="pad"></div>
</span>
<div class="pad"></div>
</span>
<span class="area-search">
<form method="GET">
<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="submit" value="&raquo;">
<input type="checkbox" class="layout-pushdown" name="rx" value="1" title="PCRE Regular Expression" ` + attr(this.queryIsRegex, "checked") + `>
</form>
</span>
</div>
<span class="area-search">
<form method="GET">
<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="submit" value="&raquo;">
<input type="checkbox" class="layout-pushdown" name="rx" value="1" title="Regular Expression" ` + attr(this.queryIsRegex, "checked") + `>
</form>
</span>
</div>
<div class="layout-body" id="chatarea">
<div class="layout-body" id="chatarea">
`))
// Header ends

View File

@ -3,14 +3,8 @@
var alreadyLoaded = false;
var $chatArea = document.getElementById("chatarea");
var $selHub = document.getElementById("selHub");
var $frmHub = document.getElementById("frmHub");
var DEFAULT_FONT_SIZE = 12;
function urldesc(s) {
return decodeURIComponent(s.replace(/\+/g, " "));
}
function cookie_set(key, value) {
document.cookie = (key+"="+value+"; expires=Sat, 20 Sep 2059 09:05:12; path=/");
}
@ -29,7 +23,11 @@ function cookie_get(key) {
return null;
}
function highlight(str) {
function highlight(str) {
var urldesc = function(s) {
return decodeURIComponent(s.replace(/\+/g, " "));
};
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(
@ -104,22 +102,6 @@ function onLoad() {
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);