mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 08:04:26 +00:00
load more button
This commit is contained in:
parent
ae0c8427d2
commit
3d23c96166
2
main.go
2
main.go
|
@ -51,7 +51,7 @@ func init() {
|
||||||
md = goldmark.New(goldmark.WithExtensions(extension.Linkify))
|
md = goldmark.New(goldmark.WithExtensions(extension.Linkify))
|
||||||
templates = make(map[string]*template.Template)
|
templates = make(map[string]*template.Template)
|
||||||
if !*watch {
|
if !*watch {
|
||||||
for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html"} {
|
for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html", "xhr.html"} {
|
||||||
t := template.New(name).Funcs(funcMap)
|
t := template.New(name).Funcs(funcMap)
|
||||||
glob, err := t.ParseGlob("templates/*")
|
glob, err := t.ParseGlob("templates/*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -121,6 +121,9 @@ code {
|
||||||
[disabled] {
|
[disabled] {
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
#loadmore [disabled] {
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
.post .title {
|
.post .title {
|
||||||
color: #888;
|
color: #888;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
@ -357,6 +360,7 @@ form.nsfw div {
|
||||||
}
|
}
|
||||||
.pager {
|
.pager {
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
.pager a {
|
.pager a {
|
||||||
padding: 1px 4px;
|
padding: 1px 4px;
|
||||||
|
@ -367,6 +371,9 @@ form.nsfw div {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: #369;
|
color: #369;
|
||||||
}
|
}
|
||||||
|
#loadmore {
|
||||||
|
margin: 10px 0px;
|
||||||
|
}
|
||||||
.buttons li {
|
.buttons li {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
@ -457,14 +464,14 @@ form.nsfw div {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
resize: both;
|
resize: both;
|
||||||
width: 100%;
|
max-width: 100%;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: contain;
|
background-size: contain;
|
||||||
background-position: top left;
|
background-position: top left;
|
||||||
}
|
}
|
||||||
.expando .image img {
|
.expando .image img {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
.expando .md {
|
.expando .md {
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
|
@ -712,6 +719,9 @@ nav .communities a.more {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
|
.dark nav .communities a.more {
|
||||||
|
background-color: #cccccc;
|
||||||
|
}
|
||||||
.orangered, .orangered b {
|
.orangered, .orangered b {
|
||||||
color: orangered !important;
|
color: orangered !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,24 @@ function commentClick(e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function loadMore(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
page = e.target.getAttribute("data-page")
|
||||||
|
e.target.disabled="disabled"
|
||||||
|
e.target.value="loading"
|
||||||
|
var urlParams = new URLSearchParams(window.location.search);
|
||||||
|
urlParams.set("xhr", "1")
|
||||||
|
urlParams.set("page", page)
|
||||||
|
request(window.location.origin+window.location.pathname+"?"+urlParams.toString(), "", function(res){
|
||||||
|
if (res.trim()) {
|
||||||
|
e.target.outerHTML = res + '<div id="loadmore"><input type="submit" data-page="'+(parseInt(page)+1)+'" value="load more" onclick="loadMore(event)"></div>'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
e.target.outerHTML = ""
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
function hideAllChildComments(e) {
|
function hideAllChildComments(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
var comments = document.getElementsByClassName("comment")
|
var comments = document.getElementsByClassName("comment")
|
||||||
|
|
11
routes.go
11
routes.go
|
@ -351,7 +351,11 @@ func GetFrontpage(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
||||||
if state.Op == "" {
|
if state.Op == "" {
|
||||||
state.GetPosts()
|
state.GetPosts()
|
||||||
}
|
}
|
||||||
Render(w, "frontpage.html", state)
|
if state.XHR {
|
||||||
|
Render(w, "xhr.html", state)
|
||||||
|
} else {
|
||||||
|
Render(w, "frontpage.html", state)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func GetPost(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
|
@ -508,10 +512,11 @@ func Settings(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
setCookie(w, state.Host, name, r.FormValue(name))
|
setCookie(w, state.Host, name, r.FormValue(name))
|
||||||
}
|
}
|
||||||
if r.FormValue("darkmode") != "" {
|
if r.FormValue("darkmode") != "" {
|
||||||
setCookie(w, state.Host, "Dark", "1")
|
setCookie(w, "", "Dark", "1")
|
||||||
state.Dark = true
|
state.Dark = true
|
||||||
} else {
|
} else {
|
||||||
deleteCookie(w, state.Host, "Dark")
|
deleteCookie(w, state.Host, "Dark")
|
||||||
|
deleteCookie(w, "", "Dark")
|
||||||
state.Dark = false
|
state.Dark = false
|
||||||
}
|
}
|
||||||
if r.FormValue("shownsfw") != "" {
|
if r.FormValue("shownsfw") != "" {
|
||||||
|
@ -934,6 +939,8 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
state.Client.CreatePostLike(context.Background(), post)
|
state.Client.CreatePostLike(context.Background(), post)
|
||||||
if r.FormValue("xhr") != "" {
|
if r.FormValue("xhr") != "" {
|
||||||
state.GetPost(postid)
|
state.GetPost(postid)
|
||||||
|
state.PostID = 0
|
||||||
|
state.Op = "vote_post"
|
||||||
state.XHR = true
|
state.XHR = true
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
return
|
return
|
||||||
|
|
12
state.go
12
state.go
|
@ -235,7 +235,7 @@ func (state *State) GetComment(commentid int) {
|
||||||
ParentID: types.NewOptional(state.CommentID),
|
ParentID: types.NewOptional(state.CommentID),
|
||||||
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
|
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
|
||||||
Type: types.NewOptional(types.ListingType("All")),
|
Type: types.NewOptional(types.ListingType("All")),
|
||||||
Limit: types.NewOptional(int64(200)),
|
Limit: types.NewOptional(int64(50)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -266,17 +266,9 @@ func (state *State) GetComments() {
|
||||||
PostID: types.NewOptional(state.PostID),
|
PostID: types.NewOptional(state.PostID),
|
||||||
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
|
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
|
||||||
Type: types.NewOptional(types.ListingType("All")),
|
Type: types.NewOptional(types.ListingType("All")),
|
||||||
Limit: types.NewOptional(int64(200)),
|
Limit: types.NewOptional(int64(50)),
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
Page: types.NewOptional(int64(state.Page)),
|
||||||
})
|
})
|
||||||
if err != nil && strings.Contains(fmt.Sprintf("%v", err), "couldnt_get_comments") {
|
|
||||||
cresp, err = state.Client.Comments(context.Background(), types.GetComments{
|
|
||||||
PostID: types.NewOptional(state.PostID),
|
|
||||||
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
|
|
||||||
Type: types.NewOptional(types.ListingType("All")),
|
|
||||||
Page: types.NewOptional(int64(state.Page)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Status = http.StatusInternalServerError
|
state.Status = http.StatusInternalServerError
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
<style>
|
<style>
|
||||||
.expando-button,
|
.expando-button,
|
||||||
.minimize,
|
.minimize,
|
||||||
|
#loadmore,
|
||||||
.hidechildren {
|
.hidechildren {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
div.pager {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
.post .expando .image img {
|
.post .expando .image img {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
|
@ -45,11 +49,12 @@
|
||||||
<div class="pager">
|
<div class="pager">
|
||||||
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}">‹ prev</a>{{ end }} <a href="{{ .NextPage }}">next ›</a>
|
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}">‹ prev</a>{{ end }} <a href="{{ .NextPage }}">next ›</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="loadmore"><input type="submit" value="load more" onclick="loadMore(event)" data-page="2"></div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<script src="/_/static/utils.js?2"></script>
|
<script src="/_/static/utils.js?v=3"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
<style>
|
<style>
|
||||||
.expando-button,
|
.expando-button,
|
||||||
.minimize,
|
.minimize,
|
||||||
|
#loadmore,
|
||||||
.hidechildren {
|
.hidechildren {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
div.pager {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
.post .expando .image img {
|
.post .expando .image img {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
|
@ -116,13 +120,14 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (and (eq .CommentCount 200) (gt (index .Posts 0).Counts.Comments .CommentCount))) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
|
{{ if or .Query (eq .SearchType "Communities") (eq (len .Posts) 25) (and .Comments (gt (index .Posts 0).Counts.Comments .CommentCount)) (and .User (or (gt .User.PersonView.Counts.CommentCount 10) (gt .User.PersonView.Counts.PostCount 10))) }}
|
||||||
<div class="pager">
|
<div class="pager">
|
||||||
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}">‹ prev</a>{{ end }} <a href="{{ .NextPage }}">next ›</a>
|
view more: {{if gt .Page 1 }}<a href="{{ .PrevPage }}">‹ prev</a>{{ end }} <a href="{{ .NextPage }}">next ›</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="loadmore"><input type="submit" value="load more" onclick="loadMore(event)" data-page="2"></div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<script src="/_/static/utils.js?2"></script>
|
<script src="/_/static/utils.js?v=3"></script>
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{ if not .State.XHR }}
|
{{ if ne .State.Op "vote_post" }}
|
||||||
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if or .Post.FeaturedCommunity .Post.FeaturedLocal }} distinguished{{end}}" onclick="postClick(event)">
|
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if or .Post.FeaturedCommunity .Post.FeaturedLocal }} distinguished{{end}}" onclick="postClick(event)">
|
||||||
{{ if gt .Rank 0 }}
|
{{ if gt .Rank 0 }}
|
||||||
<div class="rank"> {{ .Rank }} </div>
|
<div class="rank"> {{ .Rank }} </div>
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<div style="margin-top: 19px;">{{ .Counts.Score }}</div>
|
<div style="margin-top: 19px;">{{ .Counts.Score }}</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if not .State.XHR}}
|
{{ if ne .State.Op "vote_post" }}
|
||||||
</div>
|
</div>
|
||||||
<div class="thumb"><div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{if .Post.ThumbnailURL.IsValid}}{{.Post.ThumbnailURL.String}}?format=jpg&thumbnail=96{{else if .Post.URL.IsValid}}/_/static/link.png{{else}}/_/static/text.png{{end}})"></div></div>
|
<div class="thumb"><div {{ if and .Post.NSFW (not (and .State.Community .State.Community.CommunityView.Community.NSFW))}}class="img-blur"{{end}} style="background-image: url({{if .Post.ThumbnailURL.IsValid}}{{.Post.ThumbnailURL.String}}?format=jpg&thumbnail=96{{else if .Post.URL.IsValid}}/_/static/link.png{{else}}/_/static/text.png{{end}})"></div></div>
|
||||||
<div class="entry">
|
<div class="entry">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{{ if .CommentID }}
|
{{ if or .PostID .CommentID }}
|
||||||
{{ range $i, $comment := .Comments }}
|
{{ range $i, $comment := .Comments }}
|
||||||
{{ template "comment.html" $comment }}
|
{{ template "comment.html" $comment }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue