X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=1944efef4a8fcc200352ccc17300b8bf148d7a63;hb=998958fbec4c4ae0aa1b856d031254b84523ab4c;hp=b7f323e95e9ab1405c3f9e385ebffaf4cd35be82;hpb=8454806e48890675178c1b4b6cbe4bb9c42b68a3;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index b7f323e..1944efe 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -256,7 +256,7 @@ function getFormPassword() { } function getSoneElement(element) { - return $(element).parents(".sone"); + return $(element).closest(".sone"); } /** @@ -560,7 +560,7 @@ function ajaxifyNotification(notification) { } function getStatus() { - $.getJSON("getStatus.ajax", {}, function(data, textStatus) { + $.getJSON("getStatus.ajax", {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { @@ -636,7 +636,7 @@ function isViewSonePage() { * * @returns The ID of the currently shown Sone */ -function getSoneId() { +function getShownSoneId() { return $("#sone .sone-id").text(); } @@ -656,10 +656,20 @@ function isViewPostPage() { * * @returns The ID of the currently shown post */ -function getPostId() { +function getShownPostId() { return $("#sone .post-id").text(); } +/** + * Returns whether the current page is the “known Sones” page. + * + * @returns {Boolean} true if the current page is the “known + * Sones” page, false otherwise + */ +function isKnownSonesPage() { + return getPageId() == "known-sones"; +} + var loadedPosts = {}; var loadedReplies = {}; @@ -670,7 +680,7 @@ function loadNewPost(postId) { loadedPosts[postId] = true; $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) { if ((data != null) && data.success) { - if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) { + if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) { return; } var firstOlderPost = null; @@ -684,7 +694,7 @@ function loadNewPost(postId) { if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { - $("#sone .post:last").append(newPost); + $("#sone #posts").append(newPost); } ajaxifyPost(newPost); newPost.slideDown(); @@ -815,6 +825,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("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "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) {