diff --git a/public/style.css b/public/style.css
index 2b8d148..b61b969 100644
--- a/public/style.css
+++ b/public/style.css
@@ -352,6 +352,9 @@ form.nsfw div {
.gray {
color: #808080;
}
+.loading {
+ color: red !important;
+}
.error {
color: red;
font-size: 13px;
diff --git a/public/utils.js b/public/utils.js
index f1ca97d..be30024 100644
--- a/public/utils.js
+++ b/public/utils.js
@@ -105,6 +105,28 @@ function commentClick(e) {
return false
}
}
+
+function loadMoreComments(e) {
+ e.preventDefault()
+ page = e.target.getAttribute("data-page")
+ var urlParams = new URLSearchParams(window.location.search);
+ urlParams.set("xhr", "1")
+ urlParams.set("page", page)
+ e.target.innerHTML = "loading"
+ e.target.className = "loading"
+ request(window.location.origin+window.location.pathname+"?"+urlParams.toString(), "",
+ function(res){
+ if (res.trim()) {
+ e.target.parentNode.outerHTML = res + '
'
+ setup()
+ } else {
+ e.target.parentNode.outerHTML = ""
+ }
+ }, function() {
+ e.target.innerHTML = "loading failed"
+ })
+ return false;
+}
function loadMore(e) {
e.preventDefault()
page = e.target.getAttribute("data-page")
@@ -281,6 +303,9 @@ function setup() {
if (hidechildren = document.getElementById("hidechildren")){
hidechildren.addEventListener("click", hideAllChildComments)
}
+ if (lmc = document.getElementById("lmc")){
+ lmc.addEventListener("click", loadMoreComments)
+ }
var posts = document.getElementsByClassName("post")
for (var i = 0; i < posts.length; i++) {
posts[i].addEventListener("click", postClick)
@@ -313,17 +338,20 @@ if (localStorage.getItem("endlessScrolling") == "true") {
loadmore.className = "show"
loadmore.addEventListener("click", loadMore)
}
-
- if (localStorage.getItem("autoLoad") == "true") {
- window.onscroll = function(e) {
- if ((window.innerHeight + Math.round(window.scrollY)) >= document.body.offsetHeight) {
- var loadmore = document.getElementById("loadmore")
- if (loadmore) {
+}
+if (localStorage.getItem("autoLoad") == "true") {
+ window.onscroll = function(e) {
+ if ((window.innerHeight + Math.round(window.scrollY)) >= document.body.offsetHeight) {
+ if (localStorage.getItem("endlessScrolling") == "true") {
+ if (loadmore = document.getElementById("loadmore")) {
loadmore.click()
}
}
- };
- }
+ if (lmc = document.getElementById("lmc")) {
+ lmc.click()
+ }
+ }
+ };
}
// delete cookies without HTTPOnly
diff --git a/templates/frontpage.html b/templates/frontpage.html
index 39ec210..26509ad 100644
--- a/templates/frontpage.html
+++ b/templates/frontpage.html
@@ -2,7 +2,7 @@
{{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}
-
+
@@ -56,6 +56,6 @@
{{ template "sidebar.html" . }}
{{ end }}
-
+