Adding handlers to Operator
Over at labs.mozilla.com you’ll see the announcement of a microformats extension I created called Operator. I figured the release of this extension was a good reason for me to start blogging again, since people have questions and comments about the extension. So that’s what I’ll be doing here.
So far, the response has been great. Here are some posts from LouderVoice blog, microformatique, wizardishungry/blog, guillermoesteves.com, pixelsebi’s repository (in German), and Not So Relevant.
So far I think the one thing that everyone has missed about Operator is that it is extensible out of the box. Here’s an example.
I got this question on the mozilla.dev.apps.firefox newsgroup:
Will a newer version have a built in mechanism that
will allow me to extend it without it being built
into the operator extension?
For example, I want to add an additional service
such as Yedda.com to show me questions and answers
on a certain tag.
In Yedda's case (and others with similar URL structure)
it simply means the ability to add a parameterized URL
handler so I can define something like:
http://yedda.com/questions/tags/{tags}
as the handler where {tags} will be replaced by the
values of the various rel-tags on the page.
And here’s my answer:
Operator already supports this functionality. Check
out the file handler-example.js in the directory where
the extension is called. For yedda, here is what it
would look like:
Microformats.tag.handlers['yedda'] = {
description: "Find questions on Yedda",
action: function(doc, item) {
tag = Microformats.tag.create(doc,item);
url = "http://yedda.com/questions/tags/" + tag.tag;
Microformats.loadUrl(url);
}
};
Save this to a file called "yedda.js" and place it
in a directory called "microformats" in your profile
directory and you have yedda support.
So as you can see, Operator was designed to be extensible out of the box.
I’ll go into more detail about the architecture of Operator with my next post. The main thing to remember is that it is NOT a microformats toolbar! It is a microformats architecture that is currently using a toolbar as the UI. I have kept the microformats part separate from the toolbar part.