X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=01dd77c576c2d726bf4f8fcd221550e092cd036e;hb=96fcb6d250349cb1c02df44d6e3acdb93c8e7370;hp=7d7bcb557b0c07dd49a965a59f17f5933ea851fa;hpb=2dab45dd964a48144d8c919b491f792b53f5a2ea;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 7d7bcb5..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,8 +650,7 @@ function loadNewPost(postId) { loadedPosts[postId] = true; $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { - /* maybe weird timing stuff ensues. */ - if (data.post.id in loadedPosts) { + if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) { return; } var firstOlderPost = null; @@ -622,10 +660,11 @@ function loadNewPost(postId) { return false; } }); + 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(); @@ -642,10 +681,6 @@ function loadNewReply(replyId) { $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) { /* find post. */ if ((data != null) && data.success) { - /* maybe weird timing stuff ensues. */ - if (data.reply.id in loadedReplies) { - return; - } $("#sone .post#" + data.reply.postId).each(function() { var firstNewerReply = null; $(this).find(".replies .reply").each(function() { @@ -654,6 +689,7 @@ function loadNewReply(replyId) { return false; } }); + newReply = $(data.reply.html).addClass("hidden"); if (firstNewerReply != null) { newReply.insertBefore(firstNewerReply); } else { @@ -759,6 +795,21 @@ $(document).ready(function() { }); }); + /* ajaxify input field on “view Sone” page. */ + getTranslation("WebInterface.DefaultText.Message", function(defaultText) { + registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false); + $("#sone #post-message").submit(function() { + text = $(this).find(":input:enabled").val(); + $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "recipient": $("#sone #sone-id").text(), "text": text }, function(data, textStatus) { + if ((data != null) && data.success) { + loadNewPost(data.postId); + } + }); + $(this).find(":input:enabled").val("").blur(); + return false; + }); + }); + /* Ajaxifies all posts. */ /* calling getTranslation here will cache the necessary values. */ getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {