mozilla

Revision 105274 of DOM Interfaces

  • Revision slug: XBL/XBL_1.0_Reference/DOM_Interfaces
  • Revision title: DOM Interfaces
  • Revision id: 105274
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment clarification about anonymity of nodes in getAnonymousNodes's resulting NodeList; 56 words added, 1 words removed

Revision Content

 

The nsIDocumentXBL Interface

The nsIDocumentXBL interface contains methods for loading and obtaining binding documents. The interface is implemented by DOM documents that support XBL.

IDL Definition

interface nsIDocumentXBL {
  NodeList getAnonymousNodes(in Element elt);
  Element getAnonymousElementByAttribute(in Element elt,
                                         in DOMString attrName,
                                         in DOMString attrValue);
  /* NOT IMPLEMENTED
  void addBinding(in Element elt,
                  in DOMString bindingURL);
  void removeBinding(in Element elt,
                      in DOMString bindingURL);
  */

  Element getBindingParent(in Node node);
  Document loadBindingDocument(in DOMString documentURL);
};

Methods

getAnonymousNodes

The getAnonymousNodes method retrieves the anonymous children of the specified element.

  • Parameters
    • elt - The element to retrieve anonymous children for.
  • Return Value
    • NodeList - The return value of getAnonymousNodes is a NodeList that represents the children of an element after insertion points and element tags have been applied, or the "flattened tree". This means that, depending on the details regarding the insertion points of the binding, it's possible that some non-anonymous nodes appear in the list. See "Not so anonymous nodes" on mozilla.dev.platform for some discussion about this.

getAnonymousElementByAttribute

The getAnonymousElementByAttribute methods retrieves an anonymous descendant with a specified attribute value. Typically used with an (arbitrary) anonid attribute to retrieve a specific anonymous child in an XBL binding.

  • Parameters
    • elt - The element to retrieve anonymous children for.
    • attrName - The attribute name to look up.
    • attrValue - The attribute value to match.
  • Return Value
    • Element - The return value of getAnonymousElementByAttribute is an anonymous descendant of the given element with matching attribute name and value.

addBinding

NOT IMPLEMENTED The addBinding method attaches the specified binding (and any bindings that the binding inherits from) to an element. This call is not necessarily synchronous. The binding may not be attached yet when the call completes. See here for more information.

  • Parameters
    • elt - The element to attach a binding to.
    • bindingURL of type DOMString - A URI that specifies the location of a specific binding to attach.
  • No Return Value

removeBinding

NOT IMPLEMENTED The removeBinding method detaches the specified binding (and any bindings that the binding inherits from explicitly using the extends attribute) from the element. See here for more information.

  • Parameters
    • elt - The element to remove a binding from.
    • bindingURL of type DOMString - A URI that specifies the location of a specific binding to detach.
  • No Return Value

getBindingParent

The getBindingParent method is used to obtain the bound element with the binding attached that is responsible for the generation of the specified anonymous node. This method enables an author to determine the scope of any content node. When content at the document-level scope is passed in as an argument, the property's value is null.

  • Parameters
    • node - The node for which the bound element responsible for generation is desired.
  • Return Value
    • Element - The return value of getBindingParent is the element responsible for the given anonymous node.

loadBindingDocument

The loadBindingDocument method can be used to synchronously obtain the specified binding document for use within a particular document (the one on which the loadBindingDocument method was invoked). The binding document can then be modified programmatically using the DOM. Any subsequent bindings that are attached to elements within the document will be constructed from the modified binding document.

  • Parameters
    • documentURL of type DOMString - The URL of a binding document.
  • Return Value
    • Document - The return value of loadBindingDocument is the binding document used by the calling document to attach bindings that are defined in the binding document.

Example

The following snippet checks to see if any anonymous child of "element" is itself an element.

if (element.ownerDocument instanceof Ci.nsIDOMDocumentXBL)
{
    var anonChildren = element.ownerDocument.getAnonymousNodes(element);
    if (anonChildren)
    {
        for (var i = 0; i < anonChildren.length; i++)
        {
            if (anonChildren[i].nodeType == 1)
                return false;
        }
    }
}
return true; 

{{ languages( { "ja": "ja/XBL/XBL_1.0_Reference/DOM_Interfaces" } ) }}

Revision Source

<p> </p>
<h2 name="The_DocumentXBL_Interface">The nsIDocumentXBL Interface</h2>
<p>The <code>nsIDocumentXBL</code> interface contains methods for loading and obtaining binding documents. The interface is implemented by DOM documents that support XBL.</p>
<h3 name="IDL_Definition">IDL Definition</h3>
<pre>interface nsIDocumentXBL {
  NodeList getAnonymousNodes(in Element elt);
  Element getAnonymousElementByAttribute(in Element elt,
                                         in DOMString attrName,
                                         in DOMString attrValue);
  /* NOT IMPLEMENTED
  void addBinding(in Element elt,
                  in DOMString bindingURL);
  void removeBinding(in Element elt,
                      in DOMString bindingURL);
  */

  Element getBindingParent(in Node node);
  Document loadBindingDocument(in DOMString documentURL);
};
</pre>
<h3 name="Methods">Methods</h3>
<h4 name="getAnonymousNodes">getAnonymousNodes</h4>
<p>The <code>getAnonymousNodes</code> method retrieves the anonymous children of the specified element.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>elt</code> - The element to retrieve anonymous children for.</li> </ul> </li> <li><em>Return Value</em> <ul> <li><code>NodeList</code> - The return value of <code>getAnonymousNodes</code> is a <code>NodeList</code> that represents the children of an element after insertion points and element tags have been applied, or the "<a class=" external" href="http://www.w3.org/TR/xbl/#the-final" title="XML Binding Language (XBL) 2.0: The Final Flattened Tree">flattened tree</a>". This means that, depending on the details regarding the insertion points of the binding, it's possible that some non-anonymous nodes appear in the list. See <a class=" external" href="http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/d89ed07aea746c50" title="http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/d89ed07aea746c50">"Not so anonymous nodes" on mozilla.dev.platform</a> for some discussion about this.</li> </ul> </li>
</ul><h4 name="getAnonymousElementByAttribute">getAnonymousElementByAttribute</h4>
<p>The <code>getAnonymousElementByAttribute</code> methods retrieves an anonymous descendant with a specified attribute value. Typically used with an (arbitrary) <code>anonid</code> attribute to retrieve a specific anonymous child in an XBL binding.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>elt</code> - The element to retrieve anonymous children for.</li> <li><code>attrName</code> - The attribute name to look up.</li> <li><code>attrValue</code> - The attribute value to match.</li> </ul> </li> <li><em>Return Value</em> <ul> <li><code>Element</code> - The return value of <code>getAnonymousElementByAttribute</code> is an anonymous descendant of the given element with matching attribute name and value.</li> </ul> </li>
</ul>
<h4 name="addBinding">addBinding</h4>
<p><em>NOT IMPLEMENTED</em> The <code>addBinding</code> method attaches the specified binding (and any bindings that the binding inherits from) to an element. This call is not necessarily synchronous. The binding may not be attached yet when the call completes. See <a href="/en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment#Attachment_using_the_DOM" title="en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment#Attachment_using_the_DOM">here</a> for more information.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>elt</code> - The element to attach a binding to.</li> <li><code>bindingURL</code> of type <code>DOMString</code> - A URI that specifies the location of a specific binding to attach.</li> </ul> </li> <li><em>No Return Value</em></li>
</ul>
<h4 name="removeBinding">removeBinding</h4>
<p><em>NOT IMPLEMENTED</em> The <code>removeBinding</code> method detaches the specified binding (and any bindings that the binding inherits from explicitly using the <code>extends</code> attribute) from the element. See <a href="/en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment#The_bindingdetached_Event" title="en/XBL/XBL_1.0_Reference/Binding_Attachment_and_Detachment#The_bindingdetached_Event">here</a> for more information.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>elt</code> - The element to remove a binding from.</li> <li><code>bindingURL</code> of type <code>DOMString</code> - A URI that specifies the location of a specific binding to detach.</li> </ul> </li> <li><em>No Return Value</em></li>
</ul>
<h4 name="getBindingParent">getBindingParent</h4>
<p>The <code>getBindingParent</code> method is used to obtain the bound element with the binding attached that is responsible for the generation of the specified anonymous node. This method enables an author to determine the scope of any content node. When content at the document-level scope is passed in as an argument, the property's value is <code>null</code>.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>node</code> - The node for which the bound element responsible for generation is desired.</li> </ul> </li> <li><em>Return Value</em> <ul> <li><code>Element</code> - The return value of <code>getBindingParent</code> is the element responsible for the given anonymous node.</li> </ul> </li>
</ul>
<h4 name="loadBindingDocument">loadBindingDocument</h4>
<p>The <code>loadBindingDocument</code> method can be used to synchronously obtain the specified binding document for use within a particular document (the one on which the <code>loadBindingDocument </code> method was invoked). The binding document can then be modified programmatically using the DOM. Any subsequent bindings that are attached to elements within the document will be constructed from the modified binding document.</p>
<ul> <li><em>Parameters</em> <ul> <li><code>documentURL</code> of type <code><a class="external" href="http://www.w3.org/TR/2000/CR-DOM-Level-2-20000510/core.html#DOMString">DOMString</a></code> - The URL of a binding document.</li> </ul> </li> <li><em>Return Value</em> <ul> <li><code>Document</code> - The return value of <code>loadBindingDocument</code> is the binding document used by the calling document to attach bindings that are defined in the binding document.</li> </ul> </li>
</ul>
<h3>Example</h3>
<p>The following snippet checks to see if any anonymous child of "element" is itself an element.</p>
<pre>if (element.ownerDocument instanceof Ci.nsIDOMDocumentXBL)
{
    var anonChildren = element.ownerDocument.getAnonymousNodes(element);
    if (anonChildren)
    {
        for (var i = 0; i &lt; anonChildren.length; i++)
        {
            if (anonChildren[i].nodeType == 1)
                return false;
        }
    }
}
return true; 
</pre> <p>{{ languages( { "ja": "ja/XBL/XBL_1.0_Reference/DOM_Interfaces" } ) }}</p>
Revert to this revision