From: David ‘Bombe’ Roden Date: Thu, 25 Nov 2010 12:02:10 +0000 (+0100) Subject: Process replies only on success, insert before a .create-reply element. X-Git-Tag: 0.3.1-RC1~15 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=92196751abc587ed6d3dcce4432a6502907fba17;p=Sone.git Process replies only on success, insert before a .create-reply element. --- diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 6ef3e20..a860e5a 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -623,22 +623,29 @@ 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.insertAfter(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); - }); + } }); }