diff --git a/zephyr/static/js/notifications.js b/zephyr/static/js/notifications.js index 8383830340..2907ca548f 100644 --- a/zephyr/static/js/notifications.js +++ b/zephyr/static/js/notifications.js @@ -20,6 +20,7 @@ function update_title_count(new_count) { // Update window title and favicon to reflect new_message_count. // // If new_count is given, set new_message_count to that first. + var n; if (new_count !== undefined) { if (new_message_count === new_count) @@ -29,7 +30,23 @@ function update_title_count(new_count) { document.title = (new_message_count ? ("(" + new_message_count + ") ") : "") + domain + " - Humbug"; - Notificon(new_message_count || ""); + + // IE doesn't support PNG favicons, *shrug* + if (! $.browser.msie) { + // Indicate the message count in the favicon + if (new_message_count) { + // Make sure we're working with a number, as a defensive programming + // measure. And we don't have images above 99, so display those as + // 'infinite'. + n = (+new_message_count); + if (n > 99) + n = 'infinite'; + + util.set_favicon('/static/images/favicon/favicon-'+n+'.png'); + } else { + util.set_favicon('/static/favicon.ico?v=2'); + } + } } exports.initialize = function () { diff --git a/zephyr/static/js/util.js b/zephyr/static/js/util.js index e1f2ac03f6..d8c682e368 100644 --- a/zephyr/static/js/util.js +++ b/zephyr/static/js/util.js @@ -7,11 +7,22 @@ exports.random_int = function random_int(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }; +var favicon_selector = 'link[rel="shortcut icon"]'; + // We need to reset the favicon after changing the // window.location.hash or Firefox will drop the favicon. See // https://bugzilla.mozilla.org/show_bug.cgi?id=519028 exports.reset_favicon = function () { - $('link[rel="shortcut icon"]').detach().appendTo('head'); + $(favicon_selector).detach().appendTo('head'); +}; + +exports.set_favicon = function (url) { + // I'm not sure whether setting the href attr on the existing + // node would be sufficient. Notificon recreates the node. + $(favicon_selector).remove(); + $('head').append($('') + .attr('rel', 'shortcut icon') + .attr('href', url)); }; exports.make_loading_indicator = function (container, text) {