From 533527c8904a0f5952ed667c36f67f860272c2bb Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 10 Dec 2017 11:57:59 +1300 Subject: [PATCH] remove mousetrap.js (APL) in favour of accesskey; add title tags --- ArchiveState.go | 35 +++++++++++-------- YearMonth.go | 8 +++++ static/archive.js | 86 ++++++++++------------------------------------- 3 files changed, 47 insertions(+), 82 deletions(-) diff --git a/ArchiveState.go b/ArchiveState.go index 54070c6..69d5bfb 100644 --- a/ArchiveState.go +++ b/ArchiveState.go @@ -3,6 +3,7 @@ package archive import ( "bufio" "fmt" + "html" "html/template" "io/ioutil" "math" @@ -249,6 +250,11 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { nextPage = this.highestPage } + prevMonth := this.ym.Prev() // FIXME check bounds + prevMonthLink := fmt.Sprintf(`/%s/%d/%d`, this.logBestSlug, prevMonth.Year, prevMonth.Month) + nextMonth := this.ym.Next() // FIXME check bounds + nextMonthLink := fmt.Sprintf(`/%s/%d/%d`, this.logBestSlug, nextMonth.Year, nextMonth.Month) + w.Write([]byte(` @@ -260,29 +266,30 @@ func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) {
- « + « + ` + fmt.Sprintf("%d", this.page) + ` - » + + » `)) } w.Write([]byte(`
- - - -
- - - - -
- + +
+ + + + +
+
diff --git a/YearMonth.go b/YearMonth.go index 0c4e4c0..30c6c23 100644 --- a/YearMonth.go +++ b/YearMonth.go @@ -27,6 +27,14 @@ func (ym YearMonth) Next() YearMonth { } } +func (ym YearMonth) Prev() YearMonth { + if ym.Month == time.January { + return YearMonth{Year: ym.Year - 1, Month: time.December} + } else { + return YearMonth{Year: ym.Year, Month: ym.Month - 1} + } +} + // Index returns a single int that can be used to compare this YearMonth with // other YearMonth objects. func (ym YearMonth) Index() int { diff --git a/static/archive.js b/static/archive.js index 91e04a0..69e1b16 100755 --- a/static/archive.js +++ b/static/archive.js @@ -1,21 +1,13 @@ - -/* mousetrap v1.4.6 craig.is/killing/mice */ -(function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;gg||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var m={bind:function(a,b,d){a=a instanceof Array?a:[a];for(var c=0;c'); + var lines = $chatArea.innerHTML.split('
'); lines[no] = '' + lines[no] + ''; - i('chatarea').innerHTML = lines.join('
'); + $chatArea.innerHTML = lines.join('
'); } -var alreadyLoaded = false; - function onLoad() { if (alreadyLoaded) { @@ -99,7 +89,7 @@ function onLoad() { // - i('chatarea').innerHTML = highlight(i('chatarea').innerHTML); + $chatArea.innerHTML = highlight( $chatArea.innerHTML ); // @@ -117,60 +107,20 @@ function onLoad() { // - i('selHub').onchange = function() { + $selHub.onchange = function() { if ( /\/search\//.test(window.location.pathname) ) { - window.location.pathname = i('selHub').value + "/search/" + encodeURIComponent( i('searchbox').value ); + window.location.pathname = $selHub.value + "/search/" + encodeURIComponent( i('searchbox').value ); } else if ( /\/rx\//.test(window.location.pathname) ) { - window.location.pathname = i('selHub').value + "/rx/" + encodeURIComponent( i('searchbox').value ) + window.location.pathname = $selHub.value + "/rx/" + encodeURIComponent( i('searchbox').value ) } else { - i('frmHub').submit(); + $frmHub.submit(); } }; // - Mousetrap.bind('ctrl+alt+h', function() { i("pgprev").click(); }); - Mousetrap.bind('ctrl+alt+l', function() { i("pgnext").click(); }); - Mousetrap.bind('ctrl+alt+j', function() { - YMgoto( YMmod(i("seldate").value, 1) ) - }); - Mousetrap.bind('ctrl+alt+k', function() { - YMgoto( YMmod(i("seldate").value, -1) ) - }); - - Mousetrap.bind('ctrl+alt+m', function() { - i("searchbox").focus(); - }); - - // - -} - -function YMmod(str, change) { - var t = str.split('-').map(function(x) { return +x; }); - t[1] += change; - if (t[1] == 13) { - t[0] += 1; - t[1] = 1; - } - if (t[1] == 0) { - t[0] -= 1; - t[1] = 12; - } - return t.join('-'); -} - -function YMgoto(str) { - var t = str.split("-"); - i("f_y").value = t[0]; - i("f_m").value = t[1]; - i("seldate").form.submit(); -} - -function setYM(el) { - YMgoto(el.value); } window.addEventListener('load', onLoad);