From: David ‘Bombe’ Roden Date: Thu, 25 Nov 2010 14:51:20 +0000 (+0100) Subject: Mark the document title with a “(!)” when activity is detected, clear on focus. X-Git-Tag: 0.3.1-RC1~2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0c793f7f21339606808799d513d28f86f7fa6bfd;p=Sone.git Mark the document title with a “(!)” when activity is detected, clear on focus. --- diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e7d19e6..8be0282 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -569,6 +569,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 +619,7 @@ function loadNewPost(postId) { } ajaxifyPost(newPost); newPost.slideDown(); + setActivity(); } }); } @@ -650,6 +652,7 @@ function loadNewReply(replyId) { } ajaxifyReply(newReply); newReply.slideDown(); + setActivity(); }); } }); @@ -682,6 +685,20 @@ function markReplyAsKnown(replyElements) { }); } +function resetActivity() { + title = document.title; + if (title.indexOf('(') == 0) { + document.title = title.substr(title.indexOf(' ') + 1); + } +} + +function setActivity() { + title = document.title; + if (title.indexOf('(') != 0) { + document.title = "(!) " + title; + } +} + /** * Creates a new notification. * @@ -807,4 +824,10 @@ $(document).ready(function() { /* activate status polling. */ setTimeout(getStatus, 5000); + + /* reset activity counter when the page has focus. */ + $(window).focus(function() { + resetActivity(); + }); + });