all repos — honk @ cdeb724ee0d9d92782a5f48000e8ef8e81af24fe

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{{ range .Honks }}
15{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
16{{ end }}
17</main>
18{{ if $BonkCSRF }}
19<script>
20function encode(hash) {
21        var s = []
22        for (var key in hash) {
23                var val = hash[key]
24                s.push(escape(key) + "=" + escape(val))
25        }
26        return s.join("&")
27}
28function post(url, data) {
29	var x = new XMLHttpRequest()
30	x.open("POST", url)
31	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
32	x.send(data)
33}
34function bonk(el, xid) {
35	el.innerHTML = "bonked"
36	el.disabled = true
37	post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
38}
39function zonkit(el) {
40	el.innerHTML = "zonked"
41	el.disabled = true
42	var data = { }
43	var convoy, wherefore
44	for (var i in el.parentElement.elements) {
45		var e = el.parentElement.elements[i]
46		if (e.name) {
47			data[e.name] = e.value
48			if (e.name == "convoy") {
49				convoy = e.value
50			} else if (e.name == "wherefore") {
51				wherefore = e.value
52			}
53		}
54	}
55	post("/zonkit", encode(data))
56	if (wherefore == "this convoy") {
57		var els = document.querySelectorAll('article.honk')
58		for (var i = 0; i < els.length; i++) {
59			var e = els[i]
60			if (e.getAttribute("data-convoy") == convoy) {
61				e.remove()
62			}
63		}
64	}
65}
66</script>
67{{ end }}