all repos — honk @ feed6cd9157673e741c1d421053970f70eb42acd

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 = { "{{ .PageName }}" : "{{ .TopXID }}" }
 18var honksforpage = { }
 19var thispagename = "{{ .PageName }}"
 20function fillinhonks(xhr) {
 21	var doc = xhr.responseXML
 22	topxid[thispagename] = doc.children[0].children[1].children[0].innerText
 23	var honks = doc.children[0].children[1].children[1].children
 24	var honksonpage = document.getElementById("honksonpage")
 25	var lenhonks = honks.length
 26	for (var i = honks.length; i > 0; i--) {
 27		honksonpage.prepend(honks[i-1])
 28	}
 29	return lenhonks
 30}
 31function refreshhonks(btn) {
 32	btn.innerHTML = "refreshing"
 33	btn.disabled = true
 34	get("/" + thispagename + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
 35		var lenhonks = fillinhonks(xhr)
 36		btn.innerHTML = "refresh"
 37		btn.disabled = false
 38		btn.parentElement.children[1].innerHTML = " " + lenhonks + " new"
 39	})
 40}
 41function pageswitcher(name) {
 42	return function(evt) {
 43		if (name == thispagename) {
 44			return false
 45		}
 46		var honksonpage = document.getElementById("honksonpage")
 47		var holder = document.createElement("div");
 48		while (honksonpage.children.length) {
 49			holder.prepend(honksonpage.children[0])
 50		}
 51		honksforpage[thispagename] = holder
 52		thispagename = name
 53		holder = honksforpage[name]
 54		if (holder) {
 55			while (holder.children.length) {
 56				honksonpage.prepend(holder.children[0])
 57			}
 58		} else {
 59			get("/" + name + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
 60				fillinhonks(xhr)
 61			})
 62		}
 63		return false
 64	}
 65}
 66(function() {
 67	var el = document.getElementById("homelink")
 68	el.onclick = pageswitcher("home")
 69	var el = document.getElementById("atmelink")
 70	el.onclick = pageswitcher("atme")
 71})();
 72</script>
 73<p><button onclick="refreshhonks(this)">refresh</button><span></span>
 74</div>
 75{{ end }}
 76<div id="honksonpage">
 77{{ range .Honks }}
 78{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
 79{{ end }}
 80</div>
 81</main>
 82{{ if $BonkCSRF }}
 83<script>
 84function encode(hash) {
 85        var s = []
 86        for (var key in hash) {
 87                var val = hash[key]
 88                s.push(escape(key) + "=" + escape(val))
 89        }
 90        return s.join("&")
 91}
 92function post(url, data) {
 93	var x = new XMLHttpRequest()
 94	x.open("POST", url)
 95	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
 96	x.send(data)
 97}
 98function get(url, whendone) {
 99	var x = new XMLHttpRequest()
100	x.open("GET", url)
101	x.responseType = "document"
102	x.onload = function() { whendone(x) }
103	x.send()
104}
105function bonk(el, xid) {
106	el.innerHTML = "bonked"
107	el.disabled = true
108	post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
109}
110function unbonk(el, xid) {
111	el.innerHTML = "unbonked"
112	el.disabled = true
113	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
114}
115function muteit(el, convoy) {
116	el.innerHTML = "muted"
117	el.disabled = true
118	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
119	var els = document.querySelectorAll('article.honk')
120	for (var i = 0; i < els.length; i++) {
121		var e = els[i]
122		if (e.getAttribute("data-convoy") == convoy) {
123			e.remove()
124		}
125	}
126}
127function zonkit(el, xid) {
128	el.innerHTML = "zonked"
129	el.disabled = true
130	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
131	var p = el
132	while (p && p.tagName != "ARTICLE") {
133		p = p.parentElement
134	}
135	if (p) {
136		p.remove()
137	}
138}
139function ackit(el, xid) {
140	el.innerHTML = "acked"
141	el.disabled = true
142	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
143}
144function deackit(el, xid) {
145	el.innerHTML = "deacked"
146	el.disabled = true
147	post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
148}
149</script>
150{{ end }}