X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=6cb227c5c0f0bd09af370a224391eca628c92055;hb=3d438cbfcdaa81175c577fbbd31e119bb6679624;hp=8a6411825db453d557a9f49e16d41b3818470304;hpb=faa26c42ce692d20bd5c22c3e1797729d7dea9e1;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 8a64118..6cb227c 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -598,7 +598,7 @@ function loadNewPost(postId) { $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { var firstOlderPost = null; - $("#sone #posts .post").each(function() { + $("#sone .post").each(function() { if (getPostTime(this) < data.post.time) { firstOlderPost = $(this); return false; @@ -608,7 +608,7 @@ function loadNewPost(postId) { if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { - $("#sone #posts .post:last").after(newPost); + $("#sone #posts").append(newPost); } ajaxifyPost(newPost); newPost.slideDown(); @@ -623,21 +623,46 @@ function loadNewReply(replyId) { loadedReplies[replyId] = true; $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) { /* find post. */ - $("#sone #posts .post#" + data.reply.postId).each(function() { - var firstNewerReply = null; - $(this).find(".replies .reply").each(function() { - if (getReplyTime(this) > data.reply.time) { - firstNewerReply = $(this); - return false; + if ((data != null) && data.success) { + $("#sone .post#" + data.reply.postId).each(function() { + var firstNewerReply = null; + $(this).find(".replies .reply").each(function() { + if (getReplyTime(this) > data.reply.time) { + firstNewerReply = $(this); + return false; + } + }); + newReply = $(data.reply.html).addClass("hidden"); + if (firstNewerReply != null) { + newReply.insertBefore(firstNewerReply); + } else { + if ($(this).find(".replies .create-reply")) { + $(this).find(".replies .create-reply").before(newReply); + } else { + $(this).find(".replies").append(newReply); + } } + ajaxifyReply(newReply); + newReply.slideDown(); }); - newReply = $(data.reply.html); - if (firstNewerReply != null) { - newReply.insertAfter(firstNewerReply); - } else { - $(this).find(".replies .reply:last").after(newReply); - } - ajaxifyReply(newReply); + } + }); +} + +function markPostAsKnown(postElements) { + $(postElements).each(function() { + postElement = this; + $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function() { + $(postElement).removeClass("new"); + }); + }); +} + +function markReplyAsKnown(replyElements) { + $(replyElements).each(function() { + replyElement = this; + $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function() { + $(replyElement).removeClass("new"); }); }); }