all repos — honk @ f15ec859bf4470f0e2ffd702f7fc7cb12ff4c73e

my fork of honk

views/honkpage.html (view raw)

  1{{ template "header.html" . }}
  2<main>
  3<div class="info" id="infobox">
  4{{ if .Name }}
  5<p>{{ .Name }} <span style="margin-left:1em;"><a href="/u/{{ .Name }}/rss">rss</a></span>
  6<p>{{ .WhatAbout }}
  7{{ end }}
  8<p>{{ .ServerMessage }}
  9{{ if .HonkCSRF }}
 10{{ template "honkform.html" . }}
 11{{ end }}
 12</div>
 13{{ $BonkCSRF := .HonkCSRF }}
 14{{ if .TopXID }}
 15<div class="info" id="refreshbox">
 16<script>
 17var topxid = "{{ .TopXID }}"
 18function refreshhonks() {
 19	get("/?topxid=" + escape(topxid), function(xhr) {
 20		var doc = xhr.responseXML
 21		topxid = doc.children[0].children[1].children[0].innerText
 22		var honks = doc.children[0].children[1].children
 23		var mebox = document.getElementById("refreshbox")
 24		for (var i = honks.length; i > 1; i--) {
 25			mebox.insertAdjacentElement('afterend', honks[i-1])
 26		}
 27	})
 28}
 29</script>
 30<p><button onclick="refreshhonks()">refresh</button>
 31</div>
 32{{ end }}
 33{{ range .Honks }}
 34{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
 35{{ end }}
 36</main>
 37{{ if $BonkCSRF }}
 38<script>
 39function encode(hash) {
 40        var s = []
 41        for (var key in hash) {
 42                var val = hash[key]
 43                s.push(escape(key) + "=" + escape(val))
 44        }
 45        return s.join("&")
 46}
 47function post(url, data) {
 48	var x = new XMLHttpRequest()
 49	x.open("POST", url)
 50	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
 51	x.send(data)
 52}
 53function get(url, whendone) {
 54	var x = new XMLHttpRequest()
 55	x.open("GET", url)
 56	x.responseType = "document"
 57	x.onload = function() { whendone(x) }
 58	x.send()
 59}
 60function bonk(el, xid) {
 61	el.innerHTML = "bonked"
 62	el.disabled = true
 63	post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
 64}
 65function muteit(el, convoy) {
 66	el.innerHTML = "muted"
 67	el.disabled = true
 68	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
 69	var els = document.querySelectorAll('article.honk')
 70	for (var i = 0; i < els.length; i++) {
 71		var e = els[i]
 72		if (e.getAttribute("data-convoy") == convoy) {
 73			e.remove()
 74		}
 75	}
 76}
 77function zonkit(el, xid) {
 78	el.innerHTML = "zonked"
 79	el.disabled = true
 80	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
 81	var p = el
 82	while (p && p.tagName != "ARTICLE") {
 83		p = p.parentElement
 84	}
 85	if (p) {
 86		p.remove()
 87	}
 88}
 89function ackit(el, xid) {
 90	el.innerHTML = "acked"
 91	el.disabled = true
 92	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
 93}
 94function deackit(el, xid) {
 95	el.innerHTML = "deacked"
 96	el.disabled = true
 97	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
 98}
 99</script>
100{{ end }}