all repos — honk @ a570b38eb560d950c4edd30b0f7b0395912aacac

my fork of honk

views/honkpage.html (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
{{ template "header.html" . }}
<main>
<div class="info" id="infobox">
{{ if .Name }}
<p>{{ .Name }} <span style="margin-left:1em;"><a href="/u/{{ .Name }}/rss">rss</a></span>
<p>{{ .WhatAbout }}
{{ end }}
<p>{{ .ServerMessage }}
{{ if .HonkCSRF }}
{{ template "honkform.html" . }}
{{ end }}
</div>
{{ $BonkCSRF := .HonkCSRF }}
{{ if .TopXID }}
<div class="info" id="refreshbox">
<script>
var topxid = { "{{ .PageName }}" : "{{ .TopXID }}" }
var honksforpage = { }
var thispagename = "{{ .PageName }}"
function fillinhonks(xhr) {
	var doc = xhr.responseXML
	topxid[thispagename] = doc.children[0].children[1].children[0].innerText
	var honks = doc.children[0].children[1].children[1].children
	var honksonpage = document.getElementById("honksonpage")
	var lenhonks = honks.length
	for (var i = honks.length; i > 0; i--) {
		honksonpage.prepend(honks[i-1])
	}
	return lenhonks
}
function refreshhonks(btn) {
	btn.innerHTML = "refreshing"
	btn.disabled = true
	get("/" + thispagename + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
		var lenhonks = fillinhonks(xhr)
		btn.innerHTML = "refresh"
		btn.disabled = false
		btn.parentElement.children[1].innerHTML = " " + lenhonks + " new"
	})
}
function pageswitcher(name) {
	return function(evt) {
		if (name == thispagename) {
			return false
		}
		var honksonpage = document.getElementById("honksonpage")
		var holder = document.createElement("div");
		while (honksonpage.children.length) {
			holder.prepend(honksonpage.children[0])
		}
		honksforpage[thispagename] = holder
		thispagename = name
		holder = honksforpage[name]
		if (holder) {
			while (holder.children.length) {
				honksonpage.prepend(holder.children[0])
			}
		} else {
			get("/" + name + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
				fillinhonks(xhr)
			})
		}
		return false
	}
}
(function() {
	var el = document.getElementById("homelink")
	el.onclick = pageswitcher("home")
	var el = document.getElementById("atmelink")
	el.onclick = pageswitcher("atme")
})();
</script>
<p><button onclick="refreshhonks(this)">refresh</button><span></span>
</div>
{{ end }}
<div id="honksonpage">
{{ range .Honks }}
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
{{ end }}
</div>
</main>
{{ if $BonkCSRF }}
<script>
function encode(hash) {
        var s = []
        for (var key in hash) {
                var val = hash[key]
                s.push(escape(key) + "=" + escape(val))
        }
        return s.join("&")
}
function post(url, data) {
	var x = new XMLHttpRequest()
	x.open("POST", url)
	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	x.send(data)
}
function get(url, whendone) {
	var x = new XMLHttpRequest()
	x.open("GET", url)
	x.responseType = "document"
	x.onload = function() { whendone(x) }
	x.send()
}
function bonk(el, xid) {
	el.innerHTML = "bonked"
	el.disabled = true
	post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
}
function unbonk(el, xid) {
	el.innerHTML = "unbonked"
	el.disabled = true
	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
}
function muteit(el, convoy) {
	el.innerHTML = "muted"
	el.disabled = true
	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
	var els = document.querySelectorAll('article.honk')
	for (var i = 0; i < els.length; i++) {
		var e = els[i]
		if (e.getAttribute("data-convoy") == convoy) {
			e.remove()
		}
	}
}
function zonkit(el, xid) {
	el.innerHTML = "zonked"
	el.disabled = true
	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
	var p = el
	while (p && p.tagName != "ARTICLE") {
		p = p.parentElement
	}
	if (p) {
		p.remove()
	}
}
function ackit(el, xid) {
	el.innerHTML = "acked"
	el.disabled = true
	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
}
function deackit(el, xid) {
	el.innerHTML = "deacked"
	el.disabled = true
	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
}
</script>
{{ end }}