Archived
1
0

fix json rendering

This commit is contained in:
Jeff Becker 2017-09-30 08:32:51 -04:00
parent ef024977df
commit 796d3480ba
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
2 changed files with 36 additions and 9 deletions

View File

@ -264,9 +264,10 @@ func (self *post) MarshalJSON() (b []byte, err error) {
if len(self.Key) > 0 {
self.Tripcode = makeTripcode(self.Key)
}
if len(self.PostMarkup) > 0 {
if len(self.PostMessage) > 0 {
self.PostMarkup = self.RenderPost()
}
self.PostPrefix = self.Prefix()
// for liveui
self.Type = "Post"

View File

@ -46,6 +46,26 @@ var reloadImg = function(el) {
return false;
};
var reloadThreadJSON = function() {
var url = window.location.href += "/json";
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if(ajax.readyState == 4) {
if(ajax.status == 404) {
console.log("thread gone");
} else if (ajax.status == 200) {
var posts = JSON.parse(ajax.responseText);
for(var idx = 0; idx < posts.length; idx ++ )
{
}
}
}
};
ajax.open("GET", url);
ajax.send();
}
// form resubmit
onready(function() {
var submitPost = function(form, elem, cb) {
@ -89,15 +109,21 @@ onready(function() {
e.innerHTML = "posting ";
submitPost(document.forms[0], e, function(err, j) {
var msg = err || "posted";
console.log(msg, j);
console.log(msg, j.url);
e.innerHTML = msg;
setTimeout(function() {
e.disabled = false;
e.innerHTML = origText;
}, 1000);
var img = document.getElementById("captcha_img");
if (img) {
reloadImg(img);
if(window.location.pathname == j.url) {
setTimeout(function() {
e.disabled = false;
e.innerHTML = origText;
}, 1000);
var img = document.getElementById("captcha_img");
if (img) {
reloadImg(img);
}
reloadThreadJSON();
} else {
// do redirect
window.location.pathname = j.url;
}
});
}