Skip to content

Instantly share code, notes, and snippets.

@rickymoorhouse
Created September 1, 2008 12:17
Show Gist options
  • Save rickymoorhouse/8299 to your computer and use it in GitHub Desktop.
Save rickymoorhouse/8299 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "chart",
takes: {"selected text": noun_arb_text},
homepage: "http://samespirit.net/ricky",
author: { name: "Ricky Moorhouse", email: "ricky@samespirit.net"},
license: "MPL,GPL",
execute: function( text ) {
var document = context.focusedWindow.document;
text=document.getSelection();
var html_code='<img src="'+this._chartUrl(text)+'" height="30" width="150" />';
CmdUtils.setSelection(html_code);
},
_chartUrl: function (text) {
var chartUrl = "http://chart.apis.google.com/chart?";
var t = text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
var params = {
cht: "ls",
chs: "150x30",
chco: "0077CC",
chm: "B,E6F2FA,0,0,0",
chd: "t:" + t.replace(/\s/g,','),
};
return chartUrl + jQuery.param( params );
},
preview: function( pblock, directObject ) {
var text=directObject.text //context.focusedWindow.document.getSelection();
if (text.length==0) {
pblock.innerHTML='<b>WARNING:</b> You must select a text in web page to use this command !';
return;
}
var html='';
html+='You have selected <b>'+text+'</b>.<br/>';
html+='<img src="'+this._chartUrl(text)+'" height="30" width="150" />';
html+='<br>'+this._chartUrl(text);
pblock.innerHTML=html;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment