X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=75facb347af12712e821948e024dc9c5010d8a93;hb=a57e3b33c5837a40aa08c11fb92f600d928be1ab;hp=e7d19e6d4bce03ecfe22c967ca021018071e4603;hpb=95789c708a5c886410e860e72c7fca0c7f21cb17;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e7d19e6..75facb3 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -63,7 +63,7 @@ function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, op * @param element * The element to add a “comment” link to */ -function addCommentLink(postId, element) { +function addCommentLink(postId, element, insertAfterThisElement) { if ($(element).find(".show-reply-form").length > 0) { return; } @@ -86,9 +86,7 @@ function addCommentLink(postId, element) { }); return commentElement; })(postId); - $(element).find(".status-line .time").each(function() { - $(this).after(commentElement.clone(true)); - }); + $(insertAfterThisElement).after(commentElement.clone(true)); } var translations = {}; @@ -484,6 +482,9 @@ function ajaxifyPost(postElement) { return false; }); + /* add “comment” link. */ + addCommentLink(getPostId(postElement), postElement, $(postElement).find(".post-status-line .time")); + /* process all replies. */ $(postElement).find(".reply").each(function() { ajaxifyReply(this); @@ -493,12 +494,13 @@ function ajaxifyPost(postElement) { getTranslation("WebInterface.DefaultText.Reply", function(text) { $(postElement).find("input.reply-input").each(function() { registerInputTextareaSwap(this, text, "text", false, false); - addCommentLink(getPostId(postElement), postElement); }); }); - /* add “comment” link. */ - addCommentLink(getPostId(postElement), postElement); + /* mark everything as known on click. */ + $(postElement).click(function() { + markPostAsKnown(this); + }); /* hide reply input field. */ $(postElement).find(".create-reply").addClass("hidden"); @@ -528,7 +530,12 @@ function ajaxifyReply(replyElement) { }); }); })(replyElement); - addCommentLink(getPostId(replyElement), replyElement); + addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time")); + + /* mark post and all replies as known on click. */ + $(replyElement).click(function() { + markPostAsKnown(getPostElement(replyElement)); + }); } /** @@ -569,6 +576,7 @@ function getStatus() { $("#sone #notification-area").append(notification); notification.slideDown(); } + setActivity(); }); $.each(data.removedNotifications, function(index, value) { $("#sone #notification-area .notification#" + value.id).slideUp(); @@ -618,6 +626,7 @@ function loadNewPost(postId) { } ajaxifyPost(newPost); newPost.slideDown(); + setActivity(); } }); } @@ -650,6 +659,7 @@ function loadNewReply(replyId) { } ajaxifyReply(newReply); newReply.slideDown(); + setActivity(); }); } }); @@ -682,6 +692,22 @@ function markReplyAsKnown(replyElements) { }); } +function resetActivity() { + title = document.title; + if (title.indexOf('(') == 0) { + document.title = title.substr(title.indexOf(' ') + 1); + } +} + +function setActivity() { + if (!focus) { + title = document.title; + if (title.indexOf('(') != 0) { + document.title = "(!) " + title; + } + } +} + /** * Creates a new notification. * @@ -708,6 +734,8 @@ function createNotification(id, text, dismissable) { // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE // +var focus = true; + $(document).ready(function() { /* this initializes the status update input field. */ @@ -725,6 +753,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) { @@ -807,4 +850,13 @@ $(document).ready(function() { /* activate status polling. */ setTimeout(getStatus, 5000); + + /* reset activity counter when the page has focus. */ + $(window).focus(function() { + focus = true; + resetActivity(); + }).blur(function() { + focus = false; + }) + });