From 984b04cdd4748c88086e1d1ca0b060e1eaebb2a6 Mon Sep 17 00:00:00 2001 From: sostler Date: Thu, 20 May 2010 15:01:50 -0400 Subject: Consolidated away.js --- static/js/pichat.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'static/js/pichat.js') diff --git a/static/js/pichat.js b/static/js/pichat.js index c92cb62..a7caadc 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -972,3 +972,34 @@ parseUri.options = { function parseDomain(host){ return host.toLowerCase().replace(/^www\./, "") } + +// Away notification + +var UnseenMsgCounter = 0; +var OrigTitle = $('title').text(); +var HasFocus = true; + +function onFocus() { + HasFocus = true; + UnseenMsgCounter = 0; + $('title').text(OrigTitle); +} + +function onBlur() { + HasFocus = false; +} + +$(window).blur(onBlur); +$(window).focus(onFocus); + +function titleUpdater() { + if (HasFocus || UnseenMsgCounter == 0 || $('title').text() != OrigTitle) { + $('title').text(OrigTitle); + } else { + var plural = UnseenMsgCounter > 1 ? 's' : ''; + $('title').text(UnseenMsgCounter + ' new dump' + plural + '! | ' + OrigTitle); + } + setTimeout(titleUpdater, 2000); +} + +setTimeout(titleUpdater, 2000); -- cgit v1.2.3-70-g09d2