From c4338d2ae878a167c409e91dea6d1783fc7e30ba Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 18 Jul 2012 00:02:21 -0400 Subject: put away back --- static/js/src/away.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 static/js/src/away.js (limited to 'static/js/src/away.js') diff --git a/static/js/src/away.js b/static/js/src/away.js new file mode 100644 index 0000000..f669d6a --- /dev/null +++ b/static/js/src/away.js @@ -0,0 +1,31 @@ +var Away = { + "UnseenMsgCounter": 0, + "OrigTitle": "", + "HasFocus": true, + "UpdateFrequency": 3000, + + "onFocus": function() { + Away.HasFocus = true; + Away.UnseenMsgCounter = 0; + // Courtesy http://stackoverflow.com/questions/2952384/changing-the-window-title-when-focussing-the-window-doesnt-work-in-chrome + window.setTimeout(function () { $('title').text(Away.OrigTitle); }, 100); + }, + "onBlur": function() { + Away.HasFocus = false; + }, + + "updateTitle": function () { + if (Away.UnseenMsgCounter > 0) { + var plural = Away.UnseenMsgCounter > 1 ? 's' : ''; + $('title').text(Away.UnseenMsgCounter + ' new dump' + plural + '! | ' + Away.OrigTitle); + } + setTimeout(Away.updateTitle, Away.UpdateFrequency); + + }, + "startTitleUpdater": function() { + Away.OrigTitle = $('title').text(); + $(window).blur(Away.onBlur); + $(window).focus(Away.onFocus); + setTimeout(Away.updateTitle, Away.UpdateFrequency); + } +}; -- cgit v1.2.3-70-g09d2