this is extremely messy, but allow hotswap between /home and /atme
This commit is contained in:
parent
688d6be957
commit
ed7e687370
3
honk.go
3
honk.go
|
@ -173,10 +173,10 @@ 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)
|
||||
}
|
||||
|
||||
|
@ -1715,6 +1715,7 @@ func serve() {
|
|||
getters := mux.Methods("GET").Subrouter()
|
||||
|
||||
getters.HandleFunc("/", homepage)
|
||||
getters.HandleFunc("/home", homepage)
|
||||
getters.HandleFunc("/front", homepage)
|
||||
getters.HandleFunc("/robots.txt", nomoroboto)
|
||||
getters.HandleFunc("/rss", showrss)
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<span><a href="/">honk</a></span>
|
||||
<span><a id="homelink" href="/">honk</a></span>
|
||||
{{ if .UserInfo }}
|
||||
<span><a href="/atme">@me</a></span>
|
||||
<span><a id="atmelink" href="/atme">@me</a></span>
|
||||
<span><a href="/{{ .UserSep }}/{{ .UserInfo.Username }}">{{ .UserInfo.Username }}</a></span>
|
||||
<span><a href="/honkers">honkers</a></span>
|
||||
<span><a href="/c">combos</a></span>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<div>{{ .TopXID }}</div>
|
||||
{{ $BonkCSRF := .HonkCSRF }}
|
||||
<div>
|
||||
{{ range .Honks }}
|
||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
|
@ -14,31 +14,70 @@
|
|||
{{ if .TopXID }}
|
||||
<div class="info" id="refreshbox">
|
||||
<script>
|
||||
var topxid = "{{ .TopXID }}"
|
||||
var topxid = { "home" : "{{ .TopXID }}" }
|
||||
var honksforpage = { }
|
||||
var thispagename = "home"
|
||||
function fillinhonks(xhr) {
|
||||
var doc = xhr.responseXML
|
||||
topxid[thispagename] = doc.children[0].children[1].children[0].innerText
|
||||
var honks = doc.children[0].children[1].children[1].children
|
||||
var honksonpage = document.getElementById("honksonpage")
|
||||
var lenhonks = honks.length
|
||||
for (var i = honks.length; i > 0; i--) {
|
||||
honksonpage.prepend(honks[i-1])
|
||||
}
|
||||
return lenhonks
|
||||
}
|
||||
function refreshhonks(btn) {
|
||||
btn.innerHTML = "refreshing"
|
||||
btn.disabled = true
|
||||
get("/?topxid=" + escape(topxid), function(xhr) {
|
||||
var doc = xhr.responseXML
|
||||
topxid = doc.children[0].children[1].children[0].innerText
|
||||
var honks = doc.children[0].children[1].children
|
||||
var mebox = document.getElementById("refreshbox")
|
||||
var newhonks = honks.length - 1
|
||||
for (var i = honks.length; i > 1; i--) {
|
||||
mebox.insertAdjacentElement('afterend', honks[i-1])
|
||||
}
|
||||
get("/" + thispagename + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
|
||||
var lenhonks = fillinhonks(xhr)
|
||||
btn.innerHTML = "refresh"
|
||||
btn.disabled = false
|
||||
btn.parentElement.children[1].innerHTML = " " + newhonks + " new"
|
||||
btn.parentElement.children[1].innerHTML = " " + lenhonks + " new"
|
||||
})
|
||||
}
|
||||
function pageswitcher(name) {
|
||||
return function(evt) {
|
||||
if (name == thispagename) {
|
||||
return false
|
||||
}
|
||||
var honksonpage = document.getElementById("honksonpage")
|
||||
var holder = document.createElement("div");
|
||||
while (honksonpage.children.length) {
|
||||
holder.prepend(honksonpage.children[0])
|
||||
}
|
||||
honksforpage[thispagename] = holder
|
||||
thispagename = name
|
||||
holder = honksforpage[name]
|
||||
if (holder) {
|
||||
while (holder.children.length) {
|
||||
honksonpage.prepend(holder.children[0])
|
||||
}
|
||||
} else {
|
||||
get("/" + name + "?topxid=" + escape(topxid[thispagename]), function(xhr) {
|
||||
fillinhonks(xhr)
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
(function() {
|
||||
var el = document.getElementById("homelink")
|
||||
el.onclick = pageswitcher("home")
|
||||
var el = document.getElementById("atmelink")
|
||||
el.onclick = pageswitcher("atme")
|
||||
})();
|
||||
</script>
|
||||
<p><button onclick="refreshhonks(this)">refresh</button><span></span>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div id="honksonpage">
|
||||
{{ range .Honks }}
|
||||
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ if $BonkCSRF }}
|
||||
<script>
|
||||
|
|
Loading…
Reference in New Issue