X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=8a401312ca2bb18968b7c31cf6688ad9b29015dc;hb=d745c208029d06ea2cde00af631690fe6419cc3e;hp=6ef3e203368d44b6a6384a2520bf62042f5efaaa;hpb=16b4eac4cee04086b91cf5cad580a6f2f69a194b;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 6ef3e20..8a40131 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -299,7 +299,7 @@ function getPostId(element) { } function getPostTime(element) { - return getPostElement(element).find(".storage-time").text(); + return getPostElement(element).find(".post-time").text(); } function getReplyElement(element) { @@ -311,7 +311,7 @@ function getReplyId(element) { } function getReplyTime(element) { - return getReplyElement(element).find(".storage-time").text(); + return getReplyElement(element).find(".reply-time").text(); } function likePost(postId) { @@ -454,6 +454,7 @@ function ajaxifyPost(postElement) { postReply(postId, text, function(success, error, replyId) { if (success) { loadNewReply(replyId); + markPostAsKnown(getPostElement(inputField)); $("#sone .post#" + postId + " .create-reply").addClass("hidden"); } else { alert(error); @@ -623,22 +624,52 @@ 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; + if ($(postElement).hasClass("new")) { + $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) { + $(postElement).removeClass("new"); + }); + } + }); + markReplyAsKnown($(postElements).find(".reply")); +} + +function markReplyAsKnown(replyElements) { + $(replyElements).each(function() { + replyElement = this; + if ($(replyElement).hasClass("new")) { + $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) { + $(replyElement).removeClass("new"); + }); + } }); }