phorge/webroot/rsrc/js/core/Title.js
epriestley 2ecdbbec10 Don't revert Conpherence page titles when updating notifications
Summary: Fixes T7709. `JX.Title` deals with adding `(1)`, etc., counts, so send updates through it.

Test Plan: Clicked between some threads in Conpherence, no title flickering.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7709

Differential Revision: https://secure.phabricator.com/D12260
2015-04-02 13:41:48 -07:00

50 lines
887 B
JavaScript

/**
* @requires javelin-install
* @provides phabricator-title
* @javelin
*/
/**
* 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;
}
}
});