X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=bded3ce1a8031351f1d76c4c5c586a938eebe986;hb=28ab2bd3f3e4991d09682649e6b0456e6acfe016;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..bded3ce 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 {
@@ -770,30 +828,32 @@ $(document).ready(function() {
});
/* hides all replies but the latest two. */
- getTranslation("WebInterface.ClickToShow.Replies", function(text) {
- $("#sone .post .replies").each(function() {
- allReplies = $(this).find(".reply");
- if (allReplies.length > 2) {
- newHidden = false;
- for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
- $(allReplies[replyIndex]).addClass("hidden");
- newHidden |= $(allReplies[replyIndex]).hasClass("new");
- }
- clickToShowElement = $("