Skip to content

Instantly share code, notes, and snippets.

@satyr
Created January 16, 2009 10:55
Show Gist options
  • Select an option

  • Save satyr/47894 to your computer and use it in GitHub Desktop.

Select an option

Save satyr/47894 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "favicon-of-my-color",
takes: {'CSS color': noun_arb_text},
execute: function(inp){
var doc = CmdUtils.getDocument(), link = doc.createElement('link');
link.href = this._canvas(inp).toDataURL();
link.rel = 'shortcut icon';
doc.body.appendChild(link);
},
preview: function(pbl, inp){
jQuery(pbl).empty().append(this._canvas(inp));
},
previewDelay: 333,
_canvas: function(inp){
var canvas = jQuery('<canvas>')[0], size = 32, half = size / 2;
canvas.width = canvas.height = size;
with(canvas.getContext('2d')){
fillStyle = inp.text || 'silver';
arc(half, half, half - 1, 0, Math.PI * 2, false);
fill();
}
return canvas;
},
inspiredBy: 'http://gist.github.com/47877',
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment