/**
* jQuery Favicon Notify
*
* Updates the favicon to notify the user of changes. In the original tests I
* had an embedded font collection to allow any charachers - I decided that the
* ~130Kb and added complexity was overkill. As such it now uses a manual glyph
* set meaning that only numerical notifications are possible.
*
* Dual licensed under the MIT and GPL licenses:
*
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* @author David King
* @copyright Copyright (c) 2011 +
* @url oodavid.com
*/
(function($){
var canvas;
var bg = '#000000';
var fg = '#FFFFFF';
var pos = 'br';
var glyphs = [
[
' --- ',
' -@@@- ',
'-@---@-',
'-@- -@-',
'-@- -@-',
'-@- -@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' - ',
' -@- ',
'-@@- ',
' -@- ',
' -@- ',
' -@- ',
' -@- ',
'-@@@-',
' --- '
],[
' --- ',
' -@@@- ',
'-@---@-',
' - --@-',
' -@@- ',
' -@-- ',
'-@---- ',
'-@@@@@-',
' ----- '
],[
' --- ',
' -@@@- ',
'-@---@-',
' - --@-',
' -@@- ',
' - --@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' -- ',
' -@@-',
' -@-@-',
' -@--@-',
'-@---@-',
'-@@@@@-',
' ----@-',
' -@-',
' - '
],[
' ----- ',
'-@@@@@-',
'-@---- ',
'-@--- ',
'-@@@@- ',
' ----@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' --- ',
' -@@@- ',
'-@---@-',
'-@---- ',
'-@@@@- ',
'-@---@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' ----- ',
'-@@@@@-',
' ----@-',
' -@- ',
' -@- ',
' -@- ',
' -@- ',
' -@- ',
' - '
],[
' --- ',
' -@@@- ',
'-@---@-',
'-@---@-',
' -@@@- ',
'-@---@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' --- ',
' -@@@- ',
'-@---@-',
'-@---@-',
' -@@@@-',
' ----@-',
'-@---@-',
' -@@@- ',
' --- '
],[
' - ',
'-@-',
'-@-',
'-@-',
'-@-',
'-@-',
' - ',
'-@-',
' - '
]
];
$.faviconNotify = function(icon, num, myPos, myBg, myFg){
// Use the correct options
myPos = myPos || pos;
myFg = myFg || fg;
myBg = myBg || bg;
// Create a canvas if we need one
canvas = canvas || $('')[0];
if (canvas.getContext) {
// Load the favicon and manipulate it once it's loaded
var img = $('')[0];
img.onload = function () {
// Get the canvas ready and fill with the original icon
canvas.height = canvas.width = 16;
var ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0);
// We gots num?
if(num != undefined){
// Convert the num into a glyphs array
if(num > 99){
var myGlyphs = [glyphs[9], glyphs[9], glyphs[10]];
} else {
var myGlyphs = [];
num = num.toString();
$.each(num, function(k,v){
myGlyphs.push(glyphs[v]);
});
}
// Merge the glyphs together
var combined = [];
var glyphHeight = myGlyphs[0].length;
$.each(myGlyphs, function(k,v){
for(y=0; y').attr('href', canvas.toDataURL('image/png')));
};
img.src = icon;
}
};
})(jQuery);