From MozillaWiki
Jump to: navigation, search

This document provides an overview of how to add microformats to an M7 build and use them.

The microformats support currently uses Firefox 3's ability to load external scripts. Any script that is to be loaded needs to be in the modules directory where the executable is located.

Download the latest Microformats.js from bug 384186 and place it in the modules directory.

Using the microformats code is a matter of importing into your extension.


Once microformats is imported, you can use the Microformats API to access any microformats on a web page.

Note that right now, there is no way to check if a page has microformats other than using the API.

Let's go through two examples, one is accessing all of a microformat on a page, the other is accessing a particular microformat.

If you want to get all the hCards on a page, you can use the API Microformats.get.

So this would look like

var hCardArray = Microformats.get("hCard", window.document);

So this would return an array that contains all the hCards on a page.

To access items in each microformat, you use the defined property of the microformat. If something is an array in the microformat specification, it is an array in the object. So for instance, if the first hcard on this page contained a birthday, we could access it as hCardArray[0].bday.

If you have a specific DOM node on a page that you know is a microformat, you can explicitly create the microformat object:

var hcard = new hCard(document.getElementById("hcard-id"));

And again, you can access the members of the hcard directly.