Add function to detect if the current page is a “view post” page.
[Sone.git] / src / main / resources / static / javascript / sone.js
index f3ea9e8..fa2b1cf 100644 (file)
@@ -640,6 +640,26 @@ function getSoneId() {
        return $("#sone .sone-id").text();
 }
 
+/**
+ * Returns whether the current page is a “view post” page.
+ *
+ * @returns {Boolean} <code>true</code> if the current page is a “view post”
+ *          page, <code>false</code> otherwise
+ */
+function isViewPostPage() {
+       return getPageId() == "view-post";
+}
+
+/**
+ * Returns the ID of the currently shown post. This will only return a sensible
+ * value if isViewPostPage() returns <code>true</code>.
+ *
+ * @returns The ID of the currently shown post
+ */
+function getPostId() {
+       return $("#sone .post-id").text();
+}
+
 var loadedPosts = {};
 var loadedReplies = {};
 
@@ -664,7 +684,7 @@ function loadNewPost(postId) {
                        if (firstOlderPost != null) {
                                newPost.insertBefore(firstOlderPost);
                        } else {
-                               $("#sone #posts").append(newPost);
+                               $("#sone .post:last").append(newPost);
                        }
                        ajaxifyPost(newPost);
                        newPost.slideDown();