experimental refresh button. dynamic html here we come.
This commit is contained in:
parent
34f2844ffe
commit
072890112c
20
honk.go
20
honk.go
|
@ -165,10 +165,25 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
honks = gethonksforuser(userid)
|
||||
honks = osmosis(honks, userid)
|
||||
if len(honks) > 0 {
|
||||
templinfo["TopXID"] = honks[0].XID
|
||||
}
|
||||
}
|
||||
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
|
||||
}
|
||||
|
||||
tname := "honkpage.html"
|
||||
if topxid := r.FormValue("topxid"); topxid != "" {
|
||||
for i, h := range honks {
|
||||
if h.XID == topxid {
|
||||
honks = honks[0:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
log.Printf("topxid %d frags", len(honks))
|
||||
tname = "honkfrags.html"
|
||||
}
|
||||
|
||||
reverbolate(userid, honks)
|
||||
|
||||
templinfo["Honks"] = honks
|
||||
|
@ -179,7 +194,9 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
w.Header().Set("Cache-Control", "max-age=0")
|
||||
}
|
||||
err := readviews.Execute(w, "honkpage.html", templinfo)
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
|
||||
err := readviews.Execute(w, tname, templinfo)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
@ -1513,6 +1530,7 @@ func serve() {
|
|||
getconfig("debug", &debug)
|
||||
readviews = templates.Load(debug,
|
||||
"views/honkpage.html",
|
||||
"views/honkfrags.html",
|
||||
"views/honkers.html",
|
||||
"views/zonkers.html",
|
||||
"views/combos.html",
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<div>{{ .TopXID }}</div>
|
||||
{{ $BonkCSRF := .HonkCSRF }}
|
||||
{{ range .Honks }}
|
||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||
{{ end }}
|
|
@ -11,6 +11,27 @@
|
|||
{{ end }}
|
||||
</div>
|
||||
{{ $BonkCSRF := .HonkCSRF }}
|
||||
{{ if .TopXID }}
|
||||
<div class="info" id="refreshbox">
|
||||
<script>
|
||||
var topxid = {{ .TopXID }}
|
||||
function refreshhonks() {
|
||||
get("/?topxid=" + escape(topxid), function(xhr) {
|
||||
var doc = xhr.responseXML
|
||||
topel = doc.children[0].children[1].children[0]
|
||||
topxid = topel.innerText
|
||||
honks = doc.children[0].children[1].children
|
||||
var mebox = document.getElementById("refreshbox")
|
||||
for (var i = honks.length; i > 1; i--) {
|
||||
mebox.insertAdjacentElement('afterend', honks[i-1])
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<p><button onclick="refreshhonks()">refresh</button>
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
{{ range .Honks }}
|
||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||
{{ end }}
|
||||
|
@ -31,6 +52,13 @@ function post(url, data) {
|
|||
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
x.send(data)
|
||||
}
|
||||
function get(url, whendone) {
|
||||
var x = new XMLHttpRequest()
|
||||
x.open("GET", url)
|
||||
x.responseType = "document"
|
||||
x.onload = function() { whendone(x) }
|
||||
x.send()
|
||||
}
|
||||
function bonk(el, xid) {
|
||||
el.innerHTML = "bonked"
|
||||
el.disabled = true
|
||||
|
|
Loading…
Reference in New Issue