update tinycon to latest (#4850)

v1.18.x
Anil Mandepudi 9 years ago committed by Julian Lam
parent 3858e9c614
commit 1d100e9f42

@ -1,9 +1,9 @@
/*!
* Tinycon - A small library for manipulating the Favicon
* Tom Moor, http://tommoor.com
* Copyright (c) 2012 Tom Moor
* MIT Licensed
* @version 0.6.1
* Copyright (c) 2015 Tom Moor
* @license MIT Licensed
* @version 0.6.4
*/
(function(){
@ -11,7 +11,6 @@
var Tinycon = {};
var currentFavicon = null;
var originalFavicon = null;
var originalTitle = document.title;
var faviconImage = null;
var canvas = null;
var options = {};
@ -20,8 +19,8 @@
var defaults = {
width: 7,
height: 9,
font: 9 * r + 'px arial',
colour: '#ffffff',
font: 10 * r + 'px arial',
color: '#ffffff',
background: '#F03D25',
fallback: true,
crossOrigin: true,
@ -37,7 +36,7 @@
}());
var browser = {
ie: ua('msie'),
ie: ua('trident'),
chrome: ua('chrome'),
webkit: ua('chrome') || ua('safari'),
safari: ua('safari') && !ua('chrome'),
@ -50,7 +49,7 @@
var links = document.getElementsByTagName('link');
for(var i=0, len=links.length; i < len; i++) {
if ((links[i].getAttribute('rel') || '').match(/\bicon\b/)) {
if ((links[i].getAttribute('rel') || '').match(/\bicon\b/i)) {
return links[i];
}
}
@ -65,7 +64,7 @@
for(var i=0, len=links.length; i < len; i++) {
var exists = (typeof(links[i]) !== 'undefined');
if (exists && (links[i].getAttribute('rel') || '').match(/\bicon\b/)) {
if (exists && (links[i].getAttribute('rel') || '').match(/\bicon\b/i)) {
head.removeChild(links[i]);
}
}
@ -75,7 +74,10 @@
if (!originalFavicon || !currentFavicon) {
var tag = getFaviconTag();
originalFavicon = currentFavicon = tag ? tag.getAttribute('href') : '/favicon.ico';
currentFavicon = tag ? tag.getAttribute('href') : '/favicon.ico';
if (!originalFavicon) {
originalFavicon = currentFavicon;
}
}
return currentFavicon;
@ -93,6 +95,7 @@
};
var setFaviconTag = function(url){
if(url){
removeFaviconTag();
var link = document.createElement('link');
@ -100,13 +103,14 @@
link.rel = 'icon';
link.href = url;
document.getElementsByTagName('head')[0].appendChild(link);
}
};
var log = function(message){
if (window.console) window.console.log(message);
};
var drawFavicon = function(label, colour) {
var drawFavicon = function(label, color) {
// fallback to updating the browser title if unsupported
if (!getCanvas().getContext || browser.ie || browser.safari || options.fallback === 'force') {
@ -114,7 +118,7 @@
}
var context = getCanvas().getContext("2d");
var colour = colour || '#000000';
var color = color || '#000000';
var src = getCurrentFavicon();
faviconImage = document.createElement('img');
@ -127,7 +131,7 @@
context.drawImage(faviconImage, 0, 0, faviconImage.width, faviconImage.height, 0, 0, size, size);
// draw bubble over the top
if ((label + '').length > 0) drawBubble(context, label, colour);
if ((label + '').length > 0) drawBubble(context, label, color);
// refresh tag in page
refreshFavicon();
@ -145,6 +149,14 @@
var updateTitle = function(label) {
if (options.fallback) {
// Grab the current title that we can prefix with the label
var originalTitle = document.title;
// Strip out the old label if there is one
if (originalTitle[0] === '(') {
originalTitle = originalTitle.slice(originalTitle.indexOf(' '));
}
if ((label + '').length > 0) {
document.title = '(' + label + ') ' + originalTitle;
} else {
@ -153,7 +165,7 @@
}
};
var drawBubble = function(context, label, colour) {
var drawBubble = function(context, label, color) {
// automatic abbreviation for long (>2 digits) numbers
if (typeof label == 'number' && label > 99 && options.abbreviate) {
@ -199,7 +211,7 @@
context.stroke();
// label
context.fillStyle = options.colour;
context.fillStyle = options.color;
context.textAlign = "right";
context.textBaseline = "top";
@ -240,6 +252,11 @@
Tinycon.setOptions = function(custom){
options = {};
// account for deprecated UK English spelling
if (custom.colour) {
custom.color = custom.colour;
}
for(var key in defaults){
options[key] = custom.hasOwnProperty(key) ? custom[key] : defaults[key];
}
@ -252,16 +269,19 @@
return this;
};
Tinycon.setBubble = function(label, colour) {
Tinycon.setBubble = function(label, color) {
label = label || '';
drawFavicon(label, colour);
drawFavicon(label, color);
return this;
};
Tinycon.reset = function(){
currentFavicon = originalFavicon;
setFaviconTag(originalFavicon);
};
Tinycon.setOptions(defaults);
window.Tinycon = Tinycon;
})();
Loading…
Cancel
Save