From 92196751abc587ed6d3dcce4432a6502907fba17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 25 Nov 2010 13:02:10 +0100 Subject: [PATCH] Process replies only on success, insert before a .create-reply element. --- src/main/resources/static/javascript/sone.js | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) 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); - }); + } }); } -- 2.7.4