X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=fa2b1cf84372b01b57f7627447e7bf23a45c093d;hb=693da3f2d937022bca8377d95e57df8ea8ee10f9;hp=c02e240d8f2a637d9addd7c79a3b44623dae40ed;hpb=eb8d6cb360fd57eeccc692f631f6b9b7d8f41729;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index c02e240..fa2b1cf 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -601,6 +601,65 @@ 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(); +} + +/** + * Returns whether the current page is a “view post” page. + * + * @returns {Boolean} true if the current page is a “view post” + * page, false 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 true. + * + * @returns The ID of the currently shown post + */ +function getPostId() { + return $("#sone .post-id").text(); +} + var loadedPosts = {}; var loadedReplies = {}; @@ -611,6 +670,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) { @@ -618,13 +680,11 @@ function loadNewPost(postId) { return false; } }); - newPost = $(data.post.html).addClass("hidden").click(function() { - markPostAsKnown(this); - }); + newPost = $(data.post.html).addClass("hidden"); if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { - $("#sone #posts").append(newPost); + $("#sone .post:last").append(newPost); } ajaxifyPost(newPost); newPost.slideDown(); @@ -649,9 +709,7 @@ function loadNewReply(replyId) { return false; } }); - newReply = $(data.reply.html).addClass("hidden").click(function() { - markPostAsKnown(getPostElement(this)); - }); + newReply = $(data.reply.html).addClass("hidden"); if (firstNewerReply != null) { newReply.insertBefore(firstNewerReply); } else {