all repos — honk @ ab793b88d0e934bf7b621cc82b4d347db98577b6

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