X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=4b60dd91898571ddc4a075b6cd329b9f67ac743e;hb=5db08d4142418ed4e53056bdda108d4de3f879e2;hp=8be028279d2b549a4a15e9eef9c57cd3d88b1f2d;hpb=0c793f7f21339606808799d513d28f86f7fa6bfd;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 8be0282..4b60dd9 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,13 +494,9 @@ 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); - /* hide reply input field. */ $(postElement).find(".create-reply").addClass("hidden"); } @@ -528,7 +525,7 @@ function ajaxifyReply(replyElement) { }); }); })(replyElement); - addCommentLink(getPostId(replyElement), replyElement); + addCommentLink(getPostId(replyElement), replyElement, $(replyElement).find(".reply-status-line .time")); } /** @@ -611,7 +608,9 @@ function loadNewPost(postId) { return false; } }); - newPost = $(data.post.html).addClass("hidden"); + newPost = $(data.post.html).addClass("hidden").click(function() { + markPostAsKnown(this); + }); if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } else { @@ -640,7 +639,9 @@ function loadNewReply(replyId) { return false; } }); - newReply = $(data.reply.html).addClass("hidden"); + newReply = $(data.reply.html).addClass("hidden").click(function() { + markPostAsKnown(getPostElement(this)); + }); if (firstNewerReply != null) { newReply.insertBefore(firstNewerReply); } else { @@ -693,9 +694,11 @@ function resetActivity() { } function setActivity() { - title = document.title; - if (title.indexOf('(') != 0) { - document.title = "(!) " + title; + if (!focus) { + title = document.title; + if (title.indexOf('(') != 0) { + document.title = "(!) " + title; + } } } @@ -725,6 +728,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. */ @@ -827,7 +832,10 @@ $(document).ready(function() { /* reset activity counter when the page has focus. */ $(window).focus(function() { + focus = true; resetActivity(); - }); + }).blur(function() { + focus = false; + }) });