Saari Development

Ali Rizvi's Technical Blog as a Professional Software Development Engineer

Javascript: My first Mozilla Ubiquity Command

with one comment

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: "https://saaridev.wordpress.com",
  homepage: "https://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?

Advertisements

Written by imsaar

January 28, 2009 at 8:56 pm

Posted in javascript

One Response

Subscribe to comments with RSS.

  1. Hey, looks good.

    Arsalan

    February 1, 2009 at 5:14 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: