Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
Created September 26, 2008 13:28
Show Gist options
  • Save gialloporpora/13101 to your computer and use it in GitHub Desktop.
Save gialloporpora/13101 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "about-selection",
takes: {"url": noun_arb_text},
icon: "http://digg.com/favicon.ico",
homepage: "http://www.gialloporpora.netsons.org",
author: { name: "Sandro Della Giustina", email: "sandrodll@yahoo.it"},
license: "MPL,GPL",
description: "Show information about your text selection",
help: "Select a text and launch this command to view the number of selected words and characters.",
_aboutsel: function(text){
var no_sel_msg="You must select a text to use this command.";
var html='';
if (text.length>0) {
html+='<ul>';
html+='<li>You have selected <b>'+text.length+'</b> characters. </li>';
html+='<li>You have selected <b>'+text.match(/\b\w+\b/g).length+'</b> words.</li>';
html+='</ul>';
}
else html+=no_sel_msg;
return html;
},
preview: function( previewBlock, directObject){
var html=this._aboutsel(directObject.text);
previewBlock.innerHTML=CmdUtils.renderTemplate(html);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment