Archive for the ‘javascript’ Category
Javascript: My first Mozilla Ubiquity Command
I learned about Mozilla Ubiquity yesterday through my colleague Arnab Deka and I read the article about on the bus on my way back home on Instapaper iPhone application and I installed it a little over an hour ago and I am already loving it.
It already comes a lot of command built in but when I looked for a dictionary look-up command I didn’t find it. The closed was the define command which takes you to answer.com.
I thought this was a good way to add my favorite dictionary.com look up command and familiarize myself with how to add a new ubiquity command.
Here is what I came up with in less than 15 minutes using the template and tutorial:
/* This is Ali Rizvi's ubiquity first command */
CmdUtils.CreateCommand({
name: "dictionary",
// icon: "http://saaridev.wordpress.com",
homepage: "http://saaridev.wordpress.com",
author: { name: "Ali Rizvi", email: "@gmail.com"},
license: "Ruby License",
description: "Command to lookup a work on dictioanry.com",
help: "dictionary <word-to-lookup>",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
searchText = jQuery.trim(input.text);
if(searchText.length < 1) {
pblock.innerHTML = "Searches for word on dictionary.com";
return;
}
var previewTemplate = "Searches dictionary.com for <b>${query}</b>";
var previewData = {query: searchText};
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
},
execute: function(input) {
var url = "http://www.dictionary.com/browse/{QUERY}";
var query = input.text ;
var urlString = url.replace("{QUERY}", query);
Utils.openUrlInBrowser(urlString);
}
});
When I hit the save button ubiquity command editor posted this gist. Anybody know how to add js syntax highlighting on github gists?