Process replies only on success, insert before a .create-reply element.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 25 Nov 2010 12:02:10 +0000 (13:02 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 25 Nov 2010 12:02:10 +0000 (13:02 +0100)
src/main/resources/static/javascript/sone.js

index 6ef3e20..a860e5a 100644 (file)
@@ -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);
-               });
+               }
        });
 }