mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-21 21:27:15 +00:00
xhr errorcallback, login and comment score/votes in inbox
This commit is contained in:
parent
1b5c6f619e
commit
f2ca245b13
|
@ -1,8 +1,9 @@
|
|||
function request(url, params, callback) {
|
||||
function request(url, params, callback, errorcallback) {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.onreadystatechange = function() {
|
||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
|
||||
callback(xmlHttp.responseText);
|
||||
return callback(xmlHttp.responseText);
|
||||
errorcallback(xmlHttp.responseText);
|
||||
}
|
||||
var method = "GET"
|
||||
if (params) method = "POST"
|
||||
|
@ -45,9 +46,13 @@ function commentClick(e) {
|
|||
params += "&" + e.target.name + "=" + e.target.value
|
||||
params += "&xhr=1"
|
||||
e.target.disabled = "disabled"
|
||||
request(targ.target, params, function(res){
|
||||
targ.outerHTML = res
|
||||
})
|
||||
request(targ.target || "", params,
|
||||
function(res){
|
||||
targ.outerHTML = res
|
||||
},
|
||||
function(res){
|
||||
e.target.disabled = ""
|
||||
})
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -100,19 +105,24 @@ function loadMore(e) {
|
|||
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 + '<input id="loadmore" type="submit" data-page="'+(parseInt(page)+1)+'" value="load more" onclick="loadMore(event)">'
|
||||
if (showimages = document.getElementById("showimages")) {
|
||||
if (showimages.className == "selected") {
|
||||
toggle_images(true)
|
||||
request(window.location.origin+window.location.pathname+"?"+urlParams.toString(), "",
|
||||
function(res){
|
||||
if (res.trim()) {
|
||||
e.target.outerHTML = res + '<input id="loadmore" type="submit" data-page="'+(parseInt(page)+1)+'" value="load more" onclick="loadMore(event)">'
|
||||
if (showimages = document.getElementById("showimages")) {
|
||||
if (showimages.className == "selected") {
|
||||
toggle_images(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
e.target.outerHTML = '<input id="end" type="submit" value="" disabled>'
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
e.target.outerHTML = '<input id="end" type="submit" value="loading failed" onclick="loadMore(event)">'
|
||||
}
|
||||
else {
|
||||
e.target.outerHTML = '<input id="end" type="submit" value="" disabled>'
|
||||
}
|
||||
})
|
||||
)
|
||||
return false;
|
||||
}
|
||||
function hideAllChildComments(e) {
|
||||
|
@ -146,9 +156,14 @@ function formSubmit(e) {
|
|||
params += "&" + e.submitter.name + "=" + e.submitter.value
|
||||
params += "&xhr=1"
|
||||
e.submitter.disabled = "disabled"
|
||||
request(targ.target, params, function(res){
|
||||
targ.outerHTML = res
|
||||
})
|
||||
request(targ.target, params,
|
||||
function(res){
|
||||
targ.outerHTML = res
|
||||
},
|
||||
function(res){
|
||||
e.submitter.disabled = ""
|
||||
}
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -1061,6 +1061,7 @@ func GetRouter() *httprouter.Router {
|
|||
router.GET("/:host/search", middleware(Search))
|
||||
router.POST("/:host/search", middleware(UserOp))
|
||||
router.GET("/:host/inbox", middleware(Inbox))
|
||||
router.POST("/:host/inbox", middleware(UserOp))
|
||||
router.GET("/:host/login", middleware(GetLogin))
|
||||
router.POST("/:host/login", middleware(SignUpOrLogin))
|
||||
router.GET("/:host/settings", middleware(Settings))
|
||||
|
@ -1091,6 +1092,7 @@ func GetRouter() *httprouter.Router {
|
|||
router.GET("/search", middleware(Search))
|
||||
router.POST("/search", middleware(UserOp))
|
||||
router.GET("/inbox", middleware(Inbox))
|
||||
router.POST("/inbox", middleware(UserOp))
|
||||
router.GET("/login", middleware(GetLogin))
|
||||
router.POST("/login", middleware(SignUpOrLogin))
|
||||
router.GET("/settings", middleware(Settings))
|
||||
|
|
Loading…
Reference in a new issue