X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=01dd77c576c2d726bf4f8fcd221550e092cd036e;hp=75facb347af12712e821948e024dc9c5010d8a93;hb=96fcb6d250349cb1c02df44d6e3acdb93c8e7370;hpb=bd56e01d9efa9b54074dad9b698e98e7dc2be46d diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 75facb3..01dd77c 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -601,6 +601,45 @@ function getStatus() { }) } +/** + * Returns the content of the page-id attribute. + * + * @returns The page ID + */ +function getPageId() { + return $("#sone .page-id").text(); +} + +/** + * Returns whether the current page is the index page. + * + * @returns {Boolean} true if the current page is the index page, + * false otherwise + */ +function isIndexPage() { + return getPageId() == "index"; +} + +/** + * Returns whether the current page is a “view Sone” page. + * + * @returns {Boolean} true if the current page is a “view Sone” + * page, false otherwise + */ +function isViewSonePage() { + return getPageId() == "view-sone"; +} + +/** + * Returns the ID of the currently shown Sone. This will only return a sensible + * value if isViewSonePage() returns true. + * + * @returns The ID of the currently shown Sone + */ +function getSoneId() { + return $("#sone .sone-id").text(); +} + var loadedPosts = {}; var loadedReplies = {}; @@ -611,6 +650,9 @@ function loadNewPost(postId) { loadedPosts[postId] = true; $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { + if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) { + return; + } var firstOlderPost = null; $("#sone .post").each(function() { if (getPostTime(this) < data.post.time) { @@ -622,7 +664,7 @@ function loadNewPost(postId) { if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { - $("#sone #posts").append(newPost); + $("#sone .post:last").append(newPost); } ajaxifyPost(newPost); newPost.slideDown();