summaryrefslogtreecommitdiff
path: root/static/js/src/away.js
diff options
context:
space:
mode:
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);
+ }
+};