Move favicon-related functions to favicon.js

util.reset_favicon -> favicon.reset
util.set_favicon -> favicon.set

(imported from commit 250848ec5dc7ac58649197c8cc4b7b4e7b19f25c)
This commit is contained in:
Steve Howell 2014-03-13 12:44:43 -04:00 committed by Leo Franchi
parent 77e7947f61
commit 7fce920522
6 changed files with 42 additions and 31 deletions

35
static/js/favicon.js Normal file
View File

@ -0,0 +1,35 @@
var favicon = (function () {
var exports = {};
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 = function () {
$(favicon_selector).detach().appendTo('head');
};
exports.set = function (url) {
if ($.browser.webkit) {
// Works in Chrome 22 at least.
// Doesn't work in Firefox 10.
$(favicon_selector).attr('href', url);
} else {
// Delete and re-create the node.
// May cause excessive work by the browser
// in re-rendering the page (see #882).
$(favicon_selector).remove();
$('head').append($('<link>')
.attr('rel', 'shortcut icon')
.attr('href', url));
}
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = favicon;
}

View File

@ -49,7 +49,7 @@ exports.changehash = function (newhash) {
} }
$(document).trigger($.Event('hashchange.zulip')); $(document).trigger($.Event('hashchange.zulip'));
set_hash(newhash); set_hash(newhash);
util.reset_favicon(); favicon.reset();
}; };
// Encodes an operator list into the // Encodes an operator list into the

View File

@ -143,7 +143,7 @@ exports.redraw_title = function () {
} else { } else {
current_favicon = previous_favicon = '/static/favicon.ico?v=2'; current_favicon = previous_favicon = '/static/favicon.ico?v=2';
} }
util.set_favicon(current_favicon); favicon.set(current_favicon);
} }
if (window.bridge !== undefined) { if (window.bridge !== undefined) {
@ -158,11 +158,11 @@ function flash_pms() {
// a special icon indicating that you have unread PMs. // a special icon indicating that you have unread PMs.
if (unread.get_counts().private_message_count > 0) { if (unread.get_counts().private_message_count > 0) {
if (current_favicon === unread_pms_favicon) { if (current_favicon === unread_pms_favicon) {
util.set_favicon(previous_favicon); favicon.set(previous_favicon);
current_favicon = previous_favicon; current_favicon = previous_favicon;
previous_favicon = unread_pms_favicon; previous_favicon = unread_pms_favicon;
} else { } else {
util.set_favicon(unread_pms_favicon); favicon.set(unread_pms_favicon);
previous_favicon = current_favicon; previous_favicon = current_favicon;
current_favicon = unread_pms_favicon; current_favicon = unread_pms_favicon;
} }
@ -172,7 +172,7 @@ function flash_pms() {
flashing = false; flashing = false;
// You have no more unread PMs, so back to only showing the unread // You have no more unread PMs, so back to only showing the unread
// count. // count.
util.set_favicon(current_favicon); favicon.set(current_favicon);
} }
} }

View File

@ -7,31 +7,6 @@ exports.random_int = function random_int(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min; 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 () {
$(favicon_selector).detach().appendTo('head');
};
exports.set_favicon = function (url) {
if ($.browser.webkit) {
// Works in Chrome 22 at least.
// Doesn't work in Firefox 10.
$(favicon_selector).attr('href', url);
} else {
// Delete and re-create the node.
// May cause excessive work by the browser
// in re-rendering the page (see #882).
$(favicon_selector).remove();
$('head').append($('<link>')
.attr('rel', 'shortcut icon')
.attr('href', url));
}
};
// Like C++'s std::lower_bound. Returns the first index at which // Like C++'s std::lower_bound. Returns the first index at which
// `value` could be inserted without changing the ordering. Assumes // `value` could be inserted without changing the ordering. Assumes
// the array is sorted. // the array is sorted.

View File

@ -28,7 +28,7 @@ var globals =
+ ' message_edit tab_bar emoji popovers navigate people settings alert_words_ui message_store' + ' message_edit tab_bar emoji popovers navigate people settings alert_words_ui message_store'
+ ' avatar feature_flags search_suggestion referral stream_color Dict' + ' avatar feature_flags search_suggestion referral stream_color Dict'
+ ' Filter summary admin stream_data muting WinChan muting_ui Socket channel' + ' Filter summary admin stream_data muting WinChan muting_ui Socket channel'
+ ' message_flags bot_data loading' + ' message_flags bot_data loading favicon'
// colorspace.js // colorspace.js
+ ' colorspace' + ' colorspace'

View File

@ -550,6 +550,7 @@ JS_SPECS = {
'js/composebox_typeahead.js', 'js/composebox_typeahead.js',
'js/navigate.js', 'js/navigate.js',
'js/hotkey.js', 'js/hotkey.js',
'js/favicon.js',
'js/notifications.js', 'js/notifications.js',
'js/hashchange.js', 'js/hashchange.js',
'js/invite.js', 'js/invite.js',