honk/views/honkpage.html

151 lines
3.9 KiB
HTML

{{ 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 }}