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 |
{{ 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 = {{ .TopXID }}
function refreshhonks() {
get("/?topxid=" + escape(topxid), function(xhr) {
var doc = xhr.responseXML
topel = doc.children[0].children[1].children[0]
topxid = topel.innerText
honks = doc.children[0].children[1].children
var mebox = document.getElementById("refreshbox")
for (var i = honks.length; i > 1; i--) {
mebox.insertAdjacentElement('afterend', honks[i-1])
}
})
}
</script>
<p><button onclick="refreshhonks()">refresh</button>
</div>
{{ end }}
{{ range .Honks }}
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
{{ end }}
</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 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 }}
|