Merge pull request #1803 from chrishunt/update-favcount

Update favcount.js to v1.4.0
This commit is contained in:
Sam 2014-01-08 15:30:01 -08:00
commit d5a2c3c065

View File

@ -1,5 +1,5 @@
/* /*
* favcount.js v1.1.0 * favcount.js v1.4.0
* http://chrishunt.co/favcount * http://chrishunt.co/favcount
* Dynamically updates the favicon with a number. * Dynamically updates the favicon with a number.
* *
@ -10,7 +10,9 @@
(function(){ (function(){
function Favcount(icon) { function Favcount(icon) {
this.icon = icon; this.icon = icon;
this.opacity = 0.4;
this.canvas = document.createElement('canvas'); this.canvas = document.createElement('canvas');
this.font = "Helvetica, Arial, sans-serif";
} }
Favcount.prototype.set = function(count) { Favcount.prototype.set = function(count) {
@ -19,12 +21,12 @@
if (self.canvas.getContext) { if (self.canvas.getContext) {
img.onload = function() { img.onload = function() {
drawCanvas(self.canvas, img, normalize(count)); drawCanvas(self.canvas, self.opacity, self.font, img, normalize(count));
}; };
img.src = this.icon; img.src = this.icon;
} }
} };
function normalize(count) { function normalize(count) {
count = Math.round(count); count = Math.round(count);
@ -40,7 +42,7 @@
} }
} }
function drawCanvas(canvas, img, count) { function drawCanvas(canvas, opacity, font, img, count) {
var head = document.getElementsByTagName('head')[0], var head = document.getElementsByTagName('head')[0],
favicon = document.createElement('link'), favicon = document.createElement('link'),
multiplier, fontSize, context, xOffset, yOffset, border, shadow; multiplier, fontSize, context, xOffset, yOffset, border, shadow;
@ -57,10 +59,10 @@
canvas.height = canvas.width = img.width; canvas.height = canvas.width = img.width;
context = canvas.getContext('2d'); context = canvas.getContext('2d');
context.font = 'bold ' + fontSize + 'px "helvetica", sans-serif'; context.font = 'bold ' + fontSize + 'px ' + font;
// Draw faded favicon background // Draw faded favicon background
if (count) { context.globalAlpha = 0.4; } if (count) { context.globalAlpha = opacity; }
context.drawImage(img, 0, 0); context.drawImage(img, 0, 0);
context.globalAlpha = 1.0; context.globalAlpha = 1.0;
@ -94,5 +96,5 @@
}).call(this); }).call(this);
(function(){ (function(){
Favcount.VERSION = '1.1.0'; Favcount.VERSION = '1.4.0';
}).call(this); }).call(this);