X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=8a3780fabac744f7fbeba9413946edb1a48b5d8c;hb=78f7136b86bf5a6735ad52dab03473da6dbd88ec;hp=898c3c052ffb714865c35e2af37adbdb85a181a2;hpb=dd81126b70b09dbde157c8c80de774f4e3906bd8;p=Sone.git
diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js
index 898c3c0..8a3780f 100644
--- a/src/main/resources/static/javascript/sone.js
+++ b/src/main/resources/static/javascript/sone.js
@@ -672,19 +672,39 @@ function isKnownSonesPage() {
return getPageId() == "known-sones";
}
-var loadedPosts = {};
-var loadedReplies = {};
+/**
+ * Returns whether a post with the given ID exists on the current page.
+ *
+ * @param postId
+ * The post ID to check for
+ * @returns {Boolean} true
if a post with the given ID already
+ * exists on the page, false
otherwise
+ */
+function hasPost(postId) {
+ return $(".post#" + postId).length > 0;
+}
+
+/**
+ * Returns whether a reply with the given ID exists on the current page.
+ *
+ * @param replyId
+ * The reply ID to check for
+ * @returns {Boolean} true
if a reply with the given ID already
+ * exists on the page, false
otherwise
+ */
+function hasReply(replyId) {
+ return $("#sone .reply#" + replyId).length > 0;
+}
function loadNewPost(postId) {
- if (postId in loadedPosts) {
+ if (hasPost(postId)) {
return;
}
$.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
if ((data != null) && data.success) {
- if (data.post.id in loadedPosts) {
+ if (hasPost(data.post.id)) {
return;
}
- loadedPosts[data.post.id] = true;
if (!isIndexPage() && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) {
return;
}
@@ -709,16 +729,15 @@ function loadNewPost(postId) {
}
function loadNewReply(replyId) {
- if (replyId in loadedReplies) {
+ if (hasReply(replyId)) {
return;
}
$.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
/* find post. */
if ((data != null) && data.success) {
- if (data.reply.id in loadedReplies) {
+ if (hasReply(data.reply.id)) {
return;
}
- loadedReplies[data.reply.id] = true;
$("#sone .post#" + data.reply.postId).each(function() {
var firstNewerReply = null;
$(this).find(".replies .reply").each(function() {
@@ -823,7 +842,7 @@ $(document).ready(function() {
getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) {
registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
$("#sone #update-status").submit(function() {
- if ($(this).find(":input").hasClass("default")) {
+ if ($(this).find(":input.default:enabled").length > 0) {
return false;
}
text = $(this).find(":input:enabled").val();