From 60c5d946f5ce7acf9b84064064e7df7cc177c043 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 10 Feb 2012 16:11:56 +0100 Subject: [PATCH 1/3] expose all options --- notificon.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/notificon.js b/notificon.js index ed207b0..6c1c7dc 100644 --- a/notificon.js +++ b/notificon.js @@ -53,8 +53,12 @@ or implied, of Matt Williams. options = {}; } var defaults = { + font: "10px monospace", color: "#000000", stroke: "rgba(255,255,255,0.85)", + align: 'right', + valign: 'bottom', + width: 4, favicon: getExistingFavicon() }; for (var key in defaults) { @@ -99,18 +103,26 @@ or implied, of Matt Williams. document.getElementsByTagName('head')[0].appendChild(link); }; - var drawLabel = function drawLabel(canvas, label, color, stroke) { + var getCoords = function getCoords(options) { + return { + x: options.align.toLowerCase() === 'left' ? 0 : 16, + y: options.valign.toLowerCase() === 'top' ? 0 : 18 + }; + }; + + var drawLabel = function drawLabel(canvas, label, options) { var context = canvas.getContext("2d"); - context.font = "10px monospace"; - context.fillStyle = color; - context.textAlign = 'right'; - context.textBaseline = "top"; - context.strokeStyle = stroke; - context.lineWidth = 4; - context.strokeText(label,16,6); - context.fillText(label,16,6); + var coords = getCoords(options); + context.font = options.font; + context.fillStyle = options.color; + context.textAlign = options.align; + context.textBaseline = options.valign; + context.strokeStyle = options.stroke; + context.lineWidth = options.width; + context.strokeText(label, coords.x, coords.y); + context.fillText(label, coords.x, coords.y); }; - + var imgToCanvas = function imgToCanvas(img) { var canvas = document.createElement("canvas"); canvas.width = img.width; @@ -136,7 +148,7 @@ or implied, of Matt Williams. img.onload = function() { var canvas = imgToCanvas(img); if (label) { - drawLabel(canvas, label, options.color, options.stroke); + drawLabel(canvas, label, options); } try { return changeFavicon(canvas.toDataURL("image/png")); From 65c4aa2b0b45691d459b219cbfc07f3c002f7be7 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 10 Feb 2012 16:25:49 +0100 Subject: [PATCH 2/3] expose removeNotificon as Notificon.reset --- notificon.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notificon.js b/notificon.js index 6c1c7dc..d174a27 100644 --- a/notificon.js +++ b/notificon.js @@ -167,11 +167,15 @@ or implied, of Matt Williams. }; return true; }; - + var Notificon = function(label, options) { createNotificon(label, options); }; + Notificon.reset = function reset() { + removeNotificon(); + }; + if (typeof exports !== 'undefined') { module.exports = Notificon; } else { From 2f27d9bb1ba408d1d69f0850e4bad92047b6c887 Mon Sep 17 00:00:00 2001 From: dodo Date: Fri, 10 Feb 2012 16:46:27 +0100 Subject: [PATCH 3/3] dont expect label to be a string --- notificon.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notificon.js b/notificon.js index d174a27..174d880 100644 --- a/notificon.js +++ b/notificon.js @@ -138,7 +138,8 @@ or implied, of Matt Williams. } var options = mergeDefaultOptions(myOptions); - + + label = "" + label; if (!label.length) { return changeFavicon(options.favicon); }