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 unbonk(el, xid) {
72 el.innerHTML = "unbonked"
73 el.disabled = true
74 post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
75}
76function muteit(el, convoy) {
77 el.innerHTML = "muted"
78 el.disabled = true
79 post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
80 var els = document.querySelectorAll('article.honk')
81 for (var i = 0; i < els.length; i++) {
82 var e = els[i]
83 if (e.getAttribute("data-convoy") == convoy) {
84 e.remove()
85 }
86 }
87}
88function zonkit(el, xid) {
89 el.innerHTML = "zonked"
90 el.disabled = true
91 post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
92 var p = el
93 while (p && p.tagName != "ARTICLE") {
94 p = p.parentElement
95 }
96 if (p) {
97 p.remove()
98 }
99}
100function ackit(el, xid) {
101 el.innerHTML = "acked"
102 el.disabled = true
103 post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
104}
105function deackit(el, xid) {
106 el.innerHTML = "deacked"
107 el.disabled = true
108 post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
109}
110</script>
111{{ end }}