phorge/webroot/rsrc/js/core/Title.js
Chad Little 1fdb8ba112 JX.Favicon for Conpherence
Summary: I think maybe these should be more separate from JX.Title, but seems to work ok. May build new favicons just for messages though. Proof of concept UI.

Test Plan: Send message on one browser, see red icon in other browser. Click on menu, count and favicon switch back to normal.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D16734
2016-10-20 12:17:50 -07:00

50 lines
876 B
JavaScript

/**
* @provides phabricator-title
* @requires javelin-install
*/
/**
* Update the document title to show a notification/message count.
*/
JX.install('Title', {
statics: {
_counts: {},
_title: null,
setCount: function(k, v) {
var self = JX.Title;
self._counts[k] = v;
self._update();
},
setTitle: function(title) {
var self = JX.Title;
self._title = title;
self._update();
},
_update: function() {
var self = JX.Title;
if (self._title === null) {
self._title = document.title;
}
var sum = 0;
for (var k in self._counts) {
sum += parseInt(self._counts[k], 10) || 0;
}
var title;
if (sum) {
title = '(' + sum + ') ' + self._title;
} else {
title = self._title;
}
document.title = title;
}
}
});