El uso de microformatos

  • Enlace amigable (slug) de la revisión: El_uso_de_microformatos
  • Título de la revisión: El uso de microformatos
  • Id de la revisión: 165647
  • Creada:
  • Creador: Mgjbot
  • ¿Es la revisión actual? No
  • Comentario en to xx bot of Mgjbot

Contenido de la revisión

{{wiki.template('Traducción', [ "inglés", "Using_microformats", "en" ])}}


{{template.Fx_minversion_header(3)}} Microformats allow web sites to provide semantic data to the browser in order to make it possible to present summaries of the information on a page without having to know how to parse the document itself. Firefox 3 implements a global Microformats object that provides access to microformats. This object and its API make finding and reading microformats easy to do.

Loading the microformats API

The Microformats object is created using the new JavaScript script loader added to Firefox 3. To use the API, you need to first load the object:

Components.utils.import("resource://gre/modules/Microformats.js");

Once you've loaded the microformats API, you can manage microformats using the methods listed here; for information about parsing microformats, see Parsing microformats in JavaScript.

Predefined microformats

Firefox 3 provides definitions implementing several common microformats:

adr
Represents an address (such as a street or mailing address).
geo
Represents a geographical location using latitude and longitude.
hCard
Represents contact information for a person.
hCalendar
Represents a calendar appointment entry.
tag
Used to add tags to other microformats.

Methods

add()

Adds a new microformat to the microformat module.

{{template.Note("If a microformat by the specified name already exists, it is replaced by the new one.")}}

add(name, definition);
Parameters
<tt>name</tt>
The name of the microformat to add to the microformat module.
<tt>definition</tt>
A JavaScript structure describing the microformat. See Describing microformats in JavaScript for details.

count()

Counts the number of microformats in a document that match specified criteria.

numMicroformats = Microformats.count(name, rootElement, options);
Parameters
<tt>name</tt>
The name of the microformat to count.
<tt>rootElement</tt>
Required. The DOM element at which to begin the search. If you want to search the entire document, specify content.document.
<tt>options</tt>
Optional. If provided, this is a JavaScript object that contains zero or more of the following flags:
<tt>recurseExternalFrames</tt>
If true, child frames are included in the search. The default is true.
<tt>showHidden</tt>
If true, hidden microformats are added; otherwise they're left out. The default is false.
<tt>debug</tt>
Specify true if debug mode is in use; otherwise, specify false. The default is false.
Return value

An integer value indicating the number of microformats that match the specified criteria.

debug()

Returns a string that describes a microformat object.

{{template.Note("You can simply call <code>debug()</code> on a microformat object: <code>microformatObject.debug()</code> instead of using this method if you prefer.")}}

dumpString = debug(microformatObject)
Parameters
<tt>microformatObject</tt>
The microformat object to dump.
Return value

A string that describes the contents of the specified microformat object.

get()

Returns an array of microformat objects corresponding to the microformats found that match specified criteria.

microformatsArray = Microformats.get(name, rootElement, options, targetArray);
Parameters
<tt>name</tt>
The name of the microformat to find.
<tt>rootElement</tt>
Required. The DOM element at which to begin the search. If you want to search the entire document, specify content.document.
<tt>options</tt>
Optional. If provided, this is a JavaScript object that contains zero or more of the following flags:
<tt>recurseExternalFrames</tt>
If true, child frames that reference external content are included in the search. The default is true.
<tt>showHidden</tt>
If true, hidden microformats are added; otherwise they're left out. The default is false.
<tt>debug</tt>
Specify true if debug mode is in use; otherwise, specify false. The default is false.
<tt>targetArray</tt>
Optional. If provided, this is an array of microformat objects to which the search results are added.
Return value

A new array of microformat objects matching the search criteria, or the array specified by <tt>microformats</tt> with the newly found microformat objects added.

getNamesFromNode()

Returns a space-delineated list of microformat names that correspond to the specified microformat node.

nameList = Microformats.getNamesFromNode(node);
Parameters
<tt>node</tt>
The node for which to retrieve a list of microformat names.
Return value

If the specified <tt>node</tt> is a microformat, the result is a space-delineated string listing all the microformat names that correspond to the node. If the node isn't a microformat, nothing is returned.

getParent()

Returns the parent node of the specified microformat or child of a microformat.

parentNode = Microformats.getParent(node);
Parameters
<tt>node</tt>
The node whose parent you wish to retrieve.
Return value

The parent of the specified node. Returns nothing if the specified <tt>node</tt> isn't a microformat or the child of a microformat.

isMicroformat()

Determines whether or not the specified DOM node is a microformat.

flag = Microformats.isMicroformat(node);
Parameters
<tt>node</tt>
The DOM node to check to see if it's a microformat.
Return value

true if the node is a microformat, otherwise false.

{{template.Note("This method does <i>not</i> return <code>true</code> if the node is a child of a microformat.")}}


{{ wiki.languages( { "fr": "fr/Utilisation_de_microformats", "ja": "ja/Using_microformats", "pl": "pl/Zastosowanie_mikroformat\u00f3w", "ko": "ko/Using_microformats", "en": "en/Using_microformats" } ) }}

Fuente de la revisión

<p>{{wiki.template('Traducción', [ "inglés", "Using_microformats", "en" ])}}
</p><p><br>
{{template.Fx_minversion_header(3)}}
Microformats allow web sites to provide semantic data to the browser in order to make it possible to present summaries of the information on a page without having to know how to parse the document itself.  Firefox 3 implements a global <code>Microformats</code> object that provides access to microformats.  This object and its API make finding and reading microformats easy to do.
</p>
<h2 name="Loading_the_microformats_API">Loading the microformats API</h2>
<p>The <code>Microformats</code> object is created using the new JavaScript script loader added to Firefox 3.  To use the API, you need to first load the object:
</p>
<pre class="eval"><span class="plain">Components.utils.import("resource://gre/modules/Microformats.js");</span>
</pre>
<p>Once you've loaded the microformats API, you can manage microformats using the methods listed here; for information about parsing microformats, see <a href="es/Parsing_microformats_in_JavaScript">Parsing microformats in JavaScript</a>.
</p>
<h2 name="Predefined_microformats">Predefined microformats</h2>
<p>Firefox 3 provides definitions implementing several common microformats:
</p>
<dl><dt><code><a href="es/The_adr_microformat">adr</a></code>
</dt><dd>Represents an address (such as a street or mailing address).
</dd><dt><code><a href="es/The_geo_microformat">geo</a></code>
</dt><dd>Represents a geographical location using latitude and longitude.
</dd><dt><code><a href="es/The_hCard_microformat">hCard</a></code>
</dt><dd>Represents contact information for a person.
</dd><dt><code><a href="es/The_hCalendar_microformat">hCalendar</a></code>
</dt><dd>Represents a calendar appointment entry.
</dd><dt><code><a href="es/The_tag_microformat">tag</a></code>
</dt><dd>Used to add tags to other microformats.
</dd></dl>
<h2 name="Methods">Methods</h2>
<h3 name="add.28.29">add()</h3>
<p>Adds a new microformat to the microformat module.
</p><p>{{template.Note("If a microformat by the specified name already exists, it is replaced by the new one.")}}
</p>
<pre class="eval">add(name, definition);
</pre>
<h6 name="Parameters">Parameters</h6>
<dl><dt><tt>name</tt>
</dt><dd>The name of the microformat to add to the microformat module.
</dd><dt><tt>definition</tt>
</dt><dd>A JavaScript structure describing the microformat.  See <a href="es/Describing_microformats_in_JavaScript">Describing microformats in JavaScript</a> for details.
</dd></dl>
<h3 name="count.28.29">count()</h3>
<p>Counts the number of microformats in a document that match specified criteria.
</p>
<pre class="eval">numMicroformats = Microformats.count(name, rootElement, options);
</pre>
<h6 name="Parameters_2">Parameters</h6>
<dl><dt><tt>name</tt>
</dt><dd>The name of the microformat to count.
</dd><dt><tt>rootElement</tt>
</dt><dd>Required.  The DOM element at which to begin the search.  If you want to search the entire document, specify <code>content.document</code>.
</dd><dt><tt>options</tt>
</dt><dd>Optional.  If provided, this is a JavaScript object that contains zero or more of the following flags:
</dd></dl>
<blockquote>
<dl><dt><tt>recurseExternalFrames</tt>
</dt><dd>If <code>true</code>, child frames are included in the search.  The default is <code>true</code>.
</dd><dt><tt>showHidden</tt>
</dt><dd>If <code>true</code>, hidden microformats are added; otherwise they're left out.  The default is <code>false</code>.
</dd><dt><tt>debug</tt>
</dt><dd>Specify <code>true</code> if debug mode is in use; otherwise, specify <code>false</code>.  The default is <code>false</code>.</dd></dl></blockquote>


<h6 name="Return_value">Return value</h6>
<p>An integer value indicating the number of microformats that match the specified criteria.
</p>
<h3 name="debug.28.29">debug()</h3>
<p>Returns a string that describes a microformat object.
</p><p>{{template.Note("You can simply call &lt;code&gt;debug()&lt;/code&gt; on a microformat object: &lt;code&gt;microformatObject.debug()&lt;/code&gt; instead of using this method if you prefer.")}}
</p>
<pre class="eval">dumpString = debug(microformatObject)
</pre>
<h6 name="Parameters_3">Parameters</h6>
<dl><dt><tt>microformatObject</tt>
</dt><dd>The microformat object to dump.
</dd></dl>
<h6 name="Return_value_2">Return value</h6>
<p>A string that describes the contents of the specified microformat object.
</p>
<h3 name="get.28.29">get()</h3>
<p>Returns an array of microformat objects corresponding to the microformats found that match specified criteria.
</p>
<pre class="eval">microformatsArray = Microformats.get(name, rootElement, options, targetArray);
</pre>
<h6 name="Parameters_4">Parameters</h6>
<dl><dt><tt>name</tt>
</dt><dd>The name of the microformat to find.
</dd><dt><tt>rootElement</tt>
</dt><dd>Required.  The DOM element at which to begin the search.  If you want to search the entire document, specify <code>content.document</code>.
</dd><dt><tt>options</tt>
</dt><dd>Optional.  If provided, this is a JavaScript object that contains zero or more of the following flags:
</dd></dl>
<blockquote>
<dl><dt><tt>recurseExternalFrames</tt>
</dt><dd>If <code>true</code>, child frames that reference external content are included in the search.  The default is <code>true</code>.
</dd><dt><tt>showHidden</tt>
</dt><dd>If <code>true</code>, hidden microformats are added; otherwise they're left out.  The default is <code>false</code>.
</dd><dt><tt>debug</tt>
</dt><dd>Specify <code>true</code> if debug mode is in use; otherwise, specify <code>false</code>.  The default is <code>false</code>.</dd></dl></blockquote>


<dl><dt><tt>targetArray</tt>
</dt><dd>Optional.  If provided, this is an array of microformat objects to which the search results are added.
</dd></dl>

<h6 name="Return_value_3">Return value</h6>
<p>A new array of microformat objects matching the search criteria, or the array specified by <tt>microformats</tt> with the newly found microformat objects added.
</p>
<h3 name="getNamesFromNode.28.29">getNamesFromNode()</h3>
<p>Returns a space-delineated list of microformat names that correspond to the specified microformat node.
</p>
<pre class="eval">nameList = Microformats.getNamesFromNode(node);
</pre>
<h6 name="Parameters_5">Parameters</h6>
<dl><dt><tt>node</tt>
</dt><dd>The node for which to retrieve a list of microformat names.
</dd></dl>
<h6 name="Return_value_4">Return value</h6>
<p>If the specified <tt>node</tt> is a microformat, the result is a space-delineated string listing all the microformat names that correspond to the node.  If the node isn't a microformat, nothing is returned.
</p>
<h3 name="getParent.28.29">getParent()</h3>
<p>Returns the parent node of the specified microformat or child of a microformat.
</p>
<pre class="eval">parentNode = Microformats.getParent(node);
</pre>
<h6 name="Parameters_6">Parameters</h6>
<dl><dt><tt>node</tt>
</dt><dd>The node whose parent you wish to retrieve.
</dd></dl>
<h6 name="Return_value_5">Return value</h6>
<p>The parent of the specified node.  Returns nothing if the specified <tt>node</tt> isn't a microformat or the child of a microformat.
</p>
<h3 name="isMicroformat.28.29">isMicroformat()</h3>
<p>Determines whether or not the specified DOM node is a microformat.
</p>
<pre class="eval">flag = Microformats.isMicroformat(node);
</pre>
<h6 name="Parameters_7">Parameters</h6>
<dl><dt><tt>node</tt>
</dt><dd>The DOM node to check to see if it's a microformat.
</dd></dl>
<h6 name="Return_value_6">Return value</h6>
<p><code>true</code> if the node is a microformat, otherwise <code>false</code>.
</p><p>{{template.Note("This method does &lt;i&gt;not&lt;/i&gt; return &lt;code&gt;true&lt;/code&gt; if the node is a child of a microformat.")}}
</p><p><br>
</p>
<div class="noinclude">
</div>
<div class="noinclude">
</div>
{{ wiki.languages( { "fr": "fr/Utilisation_de_microformats", "ja": "ja/Using_microformats", "pl": "pl/Zastosowanie_mikroformat\u00f3w", "ko": "ko/Using_microformats", "en": "en/Using_microformats" } ) }}
Revertir a esta revisión