all repos — honk @ dabfdf4ee1de720202b200299ad848fffb6891e1

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