summaryrefslogtreecommitdiff
path: root/static/js/src/away.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-07-18 00:02:21 -0400
committerJules Laplace <jules@okfoc.us>2012-07-18 00:02:21 -0400
commitc4338d2ae878a167c409e91dea6d1783fc7e30ba (patch)
tree1e54fac722ac3153f9180a5a8332f2b19e11c00c /static/js/src/away.js
parentd891a7ae1b205716c086363fba17a3249a665deb (diff)
put away back
Diffstat (limited to 'static/js/src/away.js')
-rw-r--r--static/js/src/away.js31
1 files changed, 31 insertions, 0 deletions
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);
+ }
+};