summaryrefslogtreecommitdiff
path: root/static/js/src/away.js
blob: 8d910f3c0d7b3ebc1d9f2acf618e24e1bd32d88b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
window.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);
    }
};