node.js.html revision eb9b6f817df5c660be9f00fc5d27fe33479fdc98
<html>
<head>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<h3>node <span class="subtitle">3.00PR1</span></h3>
<p>
> node.js (source view)
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> Show Deprecated</span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="nx">YUI</span><span class="o">.</span><span class="nx">add</span><span class="o">(</span><span class="s1">'node'</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">Y</span><span class="o">)</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Provides a wrapper for dom nodes that supports selector queries normalizes x-browser differences.</span>
<span class="c"> * @module node</span>
<span class="c"> */</span>
<span class="c">/**</span>
<span class="c"> * A wrapper for DOM Nodes.</span>
<span class="c"> * With the exception of the noted properties,</span>
<span class="c"> * only strings, numbers, and booleans are passed through. </span>
<span class="c"> *</span>
<span class="c"> * @class Node</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">BASE_NODE</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span>
<span class="nx">ELEMENT_NODE</span> <span class="o">=</span> <span class="m">1</span><span class="o">,</span>
<span class="nx">ATTRIBUTE_NODE</span> <span class="o">=</span> <span class="m">2</span><span class="o">,</span>
<span class="nx">TEXT_NODE</span> <span class="o">=</span> <span class="m">3</span><span class="o">,</span>
<span class="nx">CDATA_SECTION_NODE</span> <span class="o">=</span> <span class="m">4</span><span class="o">,</span>
<span class="nx">ENTITY_REFERENCE_NODE</span> <span class="o">=</span> <span class="m">5</span><span class="o">,</span>
<span class="nx">ENTITY_NODE</span> <span class="o">=</span> <span class="m">6</span><span class="o">,</span>
<span class="nx">PROCESSING_INSTRUCTION_NODE</span> <span class="o">=</span> <span class="m">7</span><span class="o">,</span>
<span class="nx">COMMENT_NODE</span> <span class="o">=</span> <span class="m">8</span><span class="o">,</span>
<span class="nx">DOCUMENT_NODE</span> <span class="o">=</span> <span class="m">9</span><span class="o">,</span>
<span class="nx">DOCUMENT_TYPE_NODE</span> <span class="o">=</span> <span class="m">10</span><span class="o">,</span>
<span class="nx">DOCUMENT_FRAGMENT_NODE</span> <span class="o">=</span> <span class="m">11</span><span class="o">,</span>
<span class="nx">NOTATION_NODE</span> <span class="o">=</span> <span class="m">12</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">OWNER_DOCUMENT</span> <span class="o">=</span> <span class="s1">'ownerDocument'</span><span class="o">,</span>
<span class="nx">DEFAULT_VIEW</span> <span class="o">=</span> <span class="s1">'defaultView'</span><span class="o">,</span>
<span class="nx">PARENT_WINDOW</span> <span class="o">=</span> <span class="s1">'parentWindow'</span><span class="o">,</span>
<span class="nx">DOCUMENT_ELEMENT</span> <span class="o">=</span> <span class="s1">'documentElement'</span><span class="o">,</span>
<span class="nx">TAG_NAME</span> <span class="o">=</span> <span class="s1">'tagName'</span><span class="o">,</span>
<span class="nx">NODE_NAME</span> <span class="o">=</span> <span class="s1">'nodeName'</span><span class="o">,</span>
<span class="nx">NODE_TYPE</span> <span class="o">=</span> <span class="s1">'nodeType'</span><span class="o">,</span>
<span class="nx">COMPAT_MODE</span> <span class="o">=</span> <span class="s1">'compatMode'</span><span class="o">,</span>
<span class="nx">PARENT_NODE</span> <span class="o">=</span> <span class="s1">'parentNode'</span><span class="o">,</span>
<span class="nx">PREVIOUS_SIBLING</span> <span class="o">=</span> <span class="s1">'previousSibling'</span><span class="o">,</span>
<span class="nx">NEXT_SIBLING</span> <span class="o">=</span> <span class="s1">'nextSibling'</span><span class="o">,</span>
<span class="nx">SCROLL_TOP</span> <span class="o">=</span> <span class="s1">'scrollTop'</span><span class="o">,</span>
<span class="nx">SCROLL_LEFT</span> <span class="o">=</span> <span class="s1">'scrollLeft'</span><span class="o">,</span>
<span class="nx">COMPARE_DOCUMENT_POSITION</span> <span class="o">=</span> <span class="s1">'compareDocumentPosition'</span><span class="o">,</span>
<span class="nx">CONTAINS</span> <span class="o">=</span> <span class="s1">'contains'</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">RE_VALID_PROP_TYPES</span> <span class="o">=</span> <span class="sr">/(?:string|boolean|number)/</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">Selector</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">_instances</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">var</span> <span class="nx">_nodes</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">var</span> <span class="nx">_nodelists</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">var</span> <span class="nx">_restrict</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">slice</span> <span class="o">=</span> <span class="o">[].</span><span class="nx">slice</span><span class="o">;</span>
<span class="c">// private factory</span>
<span class="c"></span> <span class="k">var</span> <span class="nx">wrapDOM</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="kc">null</span><span class="o">,</span>
<span class="nx">yuid</span> <span class="o">=</span> <span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">?</span> <span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">:</span> <span class="kc">null</span><span class="o">,</span>
<span class="nx">instance</span> <span class="o">=</span> <span class="nx">_instances</span><span class="o">[</span><span class="nx">yuid</span><span class="o">],</span>
<span class="nx">existingNode</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">yuid</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">NODE_TYPE</span> <span class="k">in</span> <span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">instance</span> <span class="o">&&</span> <span class="nx">existingNode</span> <span class="o">&&</span> <span class="nx">node</span> <span class="o">===</span> <span class="nx">existingNode</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="nx">instance</span><span class="o">;</span> <span class="c">// reuse existing Nodes if nodes match</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Node</span><span class="o">(</span><span class="nx">node</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="s1">'item'</span> <span class="k">in</span> <span class="nx">node</span> <span class="o">||</span> <span class="s1">'push'</span> <span class="k">in</span> <span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">NodeList</span><span class="o">(</span><span class="nx">node</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ret</span><span class="o">;</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">wrapFn</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">fn</span><span class="o">(</span><span class="nx">node</span><span class="o">);</span>
<span class="o">}();</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">getDoc</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">return</span> <span class="o">(</span><span class="nx">node</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">]</span> <span class="o">===</span> <span class="m">9</span><span class="o">)</span> <span class="o">?</span> <span class="nx">node</span> <span class="o">:</span> <span class="nx">node</span><span class="o">[</span><span class="nx">OWNER_DOCUMENT</span><span class="o">];</span>
<span class="o">};</span>
<span class="c">// returns HTMLElement</span>
<span class="c"></span> <span class="k">var</span> <span class="nx">getDOMNode</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">node</span><span class="o">.</span><span class="nx">nodeType</span> <span class="o">&&</span> <span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">node</span> <span class="o">||</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Wraps the input and outputs of a node instance</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">nodeInOut</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">,</span> <span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">a</span><span class="o">)</span> <span class="o">{</span> <span class="c">// first 2 may be Node instances or nodes (TODO: or strings?)</span>
<span class="c"></span> <span class="nx">a</span> <span class="o">=</span> <span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">a</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">b</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">b</span> <span class="o">=</span> <span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">b</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">method</span><span class="o">](</span><span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">));</span>
<span class="o">};</span>
<span class="c">/*</span>
<span class="c"> * Wraps the return value in a node instance</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">nodeOut</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">,</span> <span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">method</span><span class="o">](</span><span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">));</span>
<span class="o">};</span>
<span class="c">/* </span>
<span class="c"> * Returns directy from node method call </span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">rawOut</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">,</span> <span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">method</span><span class="o">](</span><span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">);</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">noOut</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">,</span> <span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">method</span><span class="o">](</span><span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">PROPS_WRAP</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute parentNode</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'parentNode'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute childNodes</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'childNodes'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute children</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'children'</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">var</span> <span class="nx">children</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">children</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">children</span> <span class="o">===</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">childNodes</span> <span class="o">=</span> <span class="nx">node</span><span class="o">.</span><span class="nx">childNodes</span><span class="o">;</span>
<span class="nx">children</span> <span class="o">=</span> <span class="o">[];</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">childNodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">childNodes</span><span class="o">[</span><span class="nx">i</span><span class="o">][</span><span class="nx">TAG_NAME</span><span class="o">])</span> <span class="o">{</span>
<span class="nx">children</span><span class="o">[</span><span class="nx">children</span><span class="o">.</span><span class="nx">length</span><span class="o">]</span> <span class="o">=</span> <span class="nx">childNodes</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">children</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute firstChild</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'firstChild'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute lastChild</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'lastChild'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute previousSibling</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'previousSibling'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute previousSibling</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'nextSibling'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute ownerDocument</span>
<span class="c"> * @type Doc</span>
<span class="c"> */</span>
<span class="s1">'ownerDocument'</span><span class="o">:</span> <span class="nx">BASE_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute offsetParent</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'offsetParent'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute documentElement</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'documentElement'</span><span class="o">:</span> <span class="nx">DOCUMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute body</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'body'</span><span class="o">:</span> <span class="nx">DOCUMENT_NODE</span><span class="o">,</span>
<span class="c">// form</span>
<span class="c"></span> <span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute elements</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'elements'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">// table</span>
<span class="c"></span> <span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute rows</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'rows'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute cells</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'cells'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute tHead</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'tHead'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a Node instance. </span>
<span class="c"> * @attribute tFoot</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'tFoot'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a NodeList instance. </span>
<span class="c"> * @attribute tBodies</span>
<span class="c"> * @type NodeList</span>
<span class="c"> */</span>
<span class="s1">'tBodies'</span><span class="o">:</span> <span class="nx">ELEMENT_NODE</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">METHODS</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method replaceChild</span>
<span class="c"> * @param {HTMLElement | Node} node Node to be inserted </span>
<span class="c"> * @param {HTMLElement | Node} refNode Node to be replaced </span>
<span class="c"> * @return {Node} The replaced node </span>
<span class="c"> */</span>
<span class="nx">replaceChild</span><span class="o">:</span> <span class="nx">nodeInOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method appendChild</span>
<span class="c"> * @param {HTMLElement | Node} node Node to be appended </span>
<span class="c"> * @return {Node} The appended node </span>
<span class="c"> */</span>
<span class="nx">appendChild</span><span class="o">:</span> <span class="nx">nodeInOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method insertBefore</span>
<span class="c"> * @param {HTMLElement | Node} newNode Node to be appended </span>
<span class="c"> * @param {HTMLElement | Node} refNode Node to be inserted before </span>
<span class="c"> * @return {Node} The inserted node </span>
<span class="c"> */</span>
<span class="nx">insertBefore</span><span class="o">:</span> <span class="nx">nodeInOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method removeChild</span>
<span class="c"> * @param {HTMLElement | Node} node Node to be removed </span>
<span class="c"> * @return {Node} The removed node </span>
<span class="c"> */</span>
<span class="nx">removeChild</span><span class="o">:</span> <span class="nx">nodeInOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method hasChildNodes</span>
<span class="c"> * @return {Boolean} Whether or not the node has any childNodes </span>
<span class="c"> */</span>
<span class="nx">hasChildNodes</span><span class="o">:</span> <span class="nx">rawOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method cloneNode</span>
<span class="c"> * @param {HTMLElement | Node} node Node to be cloned </span>
<span class="c"> * @return {Node} The clone </span>
<span class="c"> */</span>
<span class="nx">cloneNode</span><span class="o">:</span> <span class="nx">nodeOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method getAttribute</span>
<span class="c"> * @param {String} attribute The attribute to retrieve </span>
<span class="c"> * @return {String} The current value of the attribute </span>
<span class="c"> */</span>
<span class="nx">getAttribute</span><span class="o">:</span> <span class="nx">rawOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method setAttribute</span>
<span class="c"> * @param {String} attribute The attribute to set </span>
<span class="c"> * @param {String} The value to apply to the attribute </span>
<span class="c"> */</span>
<span class="nx">setAttribute</span><span class="o">:</span> <span class="nx">noOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method hasAttribute</span>
<span class="c"> * @param {String} attribute The attribute to test for </span>
<span class="c"> * @return {Boolean} Whether or not the attribute is present </span>
<span class="c"> */</span>
<span class="nx">hasAttribute</span><span class="o">:</span> <span class="nx">rawOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method scrollIntoView</span>
<span class="c"> */</span>
<span class="nx">scrollIntoView</span><span class="o">:</span> <span class="nx">noOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method getElementsByTagName</span>
<span class="c"> * @param {String} tagName The tagName to collect </span>
<span class="c"> * @return {NodeList} A NodeList representing the HTMLCollection</span>
<span class="c"> */</span>
<span class="nx">getElementsByTagName</span><span class="o">:</span> <span class="nx">nodeOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method focus</span>
<span class="c"> */</span>
<span class="nx">focus</span><span class="o">:</span> <span class="nx">noOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * @method blur</span>
<span class="c"> */</span>
<span class="nx">blur</span><span class="o">:</span> <span class="nx">noOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * Only valid on FORM elements</span>
<span class="c"> * @method submit</span>
<span class="c"> */</span>
<span class="nx">submit</span><span class="o">:</span> <span class="nx">noOut</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Passes through to DOM method.</span>
<span class="c"> * Only valid on FORM elements</span>
<span class="c"> * @method reset</span>
<span class="c"> */</span>
<span class="nx">reset</span><span class="o">:</span> <span class="nx">noOut</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">METHODS_INVOKE</span> <span class="o">=</span> <span class="o">{</span>
<span class="s1">'getBoundingClientRect'</span><span class="o">:</span> <span class="kc">true</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">Node</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">node</span> <span class="o">||</span> <span class="o">!</span><span class="nx">node</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">])</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'invalid node:'</span> <span class="o">+</span> <span class="nx">node</span><span class="o">,</span> <span class="s1">'error'</span><span class="o">,</span> <span class="s1">'Node'</span><span class="o">);</span>
<span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">yuid</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">guid</span><span class="o">();</span>
<span class="k">try</span> <span class="o">{</span> <span class="c">// IE errors on non-element expandos (cant be reused)</span>
<span class="c"></span> <span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">=</span> <span class="nx">yuid</span><span class="o">;</span>
<span class="o">}</span> <span class="k">catch</span><span class="o">(</span><span class="nx">e</span><span class="o">)</span> <span class="o">{};</span>
<span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">=</span> <span class="nx">yuid</span><span class="o">;</span>
<span class="nx">_nodes</span><span class="o">[</span><span class="nx">yuid</span><span class="o">]</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
<span class="nx">_instances</span><span class="o">[</span><span class="nx">yuid</span><span class="o">]</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">SETTERS</span> <span class="o">=</span> <span class="o">{};</span>
<span class="k">var</span> <span class="nx">GETTERS</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Normalizes nodeInnerText and textContent. </span>
<span class="c"> * @property text</span>
<span class="c"> * @type String</span>
<span class="c"> */</span>
<span class="s1">'text'</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">node</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'innerText'</span><span class="o">)</span> <span class="o">||</span> <span class="nx">node</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="s1">'textContent'</span><span class="o">)</span> <span class="o">||</span> <span class="s1">''</span><span class="o">;</span>
<span class="o">},</span>
<span class="s1">'options'</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">?</span> <span class="nx">node</span><span class="o">.</span><span class="nx">getElementsByTagName</span><span class="o">(</span><span class="s1">'option'</span><span class="o">)</span> <span class="o">:</span> <span class="o">[];</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">setters</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">prop</span> <span class="o">==</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">SETTERS</span><span class="o">[</span><span class="nx">prop</span><span class="o">]</span> <span class="o">=</span> <span class="nx">fn</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// assume object</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">prop</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">setters</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">getters</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">prop</span> <span class="o">==</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">GETTERS</span><span class="o">[</span><span class="nx">prop</span><span class="o">]</span> <span class="o">=</span> <span class="nx">fn</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// assume object</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">prop</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">getters</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">methods</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">name</span> <span class="o">==</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">);</span>
<span class="nx">args</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
<span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">fn</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="kc">null</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">ret</span> <span class="o">===</span> <span class="kc">undefined</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ret</span><span class="o">;</span>
<span class="o">};</span>
<span class="nx">addNodeListMethod</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// assume object</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">methods</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
<span class="o">});</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="k">var</span> <span class="nx">addNodeListMethod</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">NodeList</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="o">[],</span>
<span class="nx">nodes</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span>
<span class="nx">ret</span><span class="o">;</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_nodes</span><span class="o">[</span><span class="nx">_tmpNode</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="nx">_tmpNode</span><span class="o">[</span><span class="nx">name</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="nx">nodes</span><span class="o">[</span><span class="nx">i</span><span class="o">],</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">ret</span> <span class="o">!==</span> <span class="nx">_tmpNode</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">a</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="nx">ret</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">a</span><span class="o">.</span><span class="nx">length</span> <span class="o">?</span> <span class="nx">a</span> <span class="o">:</span> <span class="k">this</span><span class="o">;</span>
<span class="o">};</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">getDOMNode</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">ret</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span><span class="o">.</span><span class="nx">nodeType</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">node</span> <span class="o">===</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="kc">null</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">ret</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ret</span> <span class="o">||</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">wrapDOMMethod</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">);</span>
<span class="nx">args</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">args</span><span class="o">.</span><span class="nx">shift</span><span class="o">()));</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">[</span><span class="nx">name</span><span class="o">].</span><span class="nx">apply</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
<span class="o">};</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">addDOMMethods</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">methods</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">add</span> <span class="o">=</span> <span class="o">{};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">methods</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">n</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">add</span><span class="o">[</span><span class="nx">v</span><span class="o">]</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">wrapDOMMethod</span><span class="o">(</span><span class="nx">v</span><span class="o">);</span>
<span class="o">});</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">methods</span><span class="o">(</span><span class="nx">add</span><span class="o">);</span>
<span class="o">};</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Set the value of the property/attribute on the HTMLElement bound to this Node.</span>
<span class="c"> * @method set</span>
<span class="c"> * @param {String} prop Property to set </span>
<span class="c"> * @param {any} val Value to apply to the given property</span>
<span class="c"> */</span>
<span class="nx">set</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">prop</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">prop</span> <span class="k">in</span> <span class="nx">SETTERS</span><span class="o">)</span> <span class="o">{</span> <span class="c">// use custom setter</span>
<span class="c"></span> <span class="nx">SETTERS</span><span class="o">[</span><span class="nx">prop</span><span class="o">](</span><span class="k">this</span><span class="o">,</span> <span class="nx">prop</span><span class="o">,</span> <span class="nx">val</span><span class="o">);</span> <span class="c">// passing Node instance</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">RE_VALID_PROP_TYPES</span><span class="o">.</span><span class="nx">test</span><span class="o">(</span><span class="k">typeof</span> <span class="nx">node</span><span class="o">[</span><span class="nx">prop</span><span class="o">]))</span> <span class="o">{</span> <span class="c">// safe to write</span>
<span class="c"></span> <span class="nx">node</span><span class="o">[</span><span class="nx">prop</span><span class="o">]</span> <span class="o">=</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Get the value of the property/attribute on the HTMLElement bound to this Node.</span>
<span class="c"> * @method get</span>
<span class="c"> * @param {String} prop Property to get </span>
<span class="c"> * @return {any} Current value of the property</span>
<span class="c"> */</span>
<span class="nx">get</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">prop</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">val</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">prop</span> <span class="k">in</span> <span class="nx">GETTERS</span><span class="o">)</span> <span class="o">{</span> <span class="c">// use custom getter</span>
<span class="c"></span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">GETTERS</span><span class="o">[</span><span class="nx">prop</span><span class="o">](</span><span class="k">this</span><span class="o">,</span> <span class="nx">prop</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">prop</span> <span class="k">in</span> <span class="nx">PROPS_WRAP</span><span class="o">)</span> <span class="o">{</span> <span class="c">// wrap DOM object (HTMLElement, HTMLCollection, Document)</span>
<span class="c"></span> <span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">PROPS_WRAP</span><span class="o">[</span><span class="nx">prop</span><span class="o">]</span> <span class="o">===</span> <span class="s1">'function'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">PROPS_WRAP</span><span class="o">[</span><span class="nx">prop</span><span class="o">](</span><span class="k">this</span><span class="o">);</span>
<span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">node</span><span class="o">[</span><span class="nx">prop</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">_restrict</span> <span class="o">&&</span> <span class="nx">_restrict</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">contains</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">val</span><span class="o">))</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span> <span class="c">// not allowed to go outside of root node</span>
<span class="c"></span> <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">val</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">RE_VALID_PROP_TYPES</span><span class="o">.</span><span class="nx">test</span><span class="o">(</span><span class="k">typeof</span> <span class="nx">node</span><span class="o">[</span><span class="nx">prop</span><span class="o">]))</span> <span class="o">{</span> <span class="c">// safe to read</span>
<span class="c"></span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">node</span><span class="o">[</span><span class="nx">prop</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">val</span><span class="o">;</span>
<span class="o">},</span>
<span class="nx">invoke</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">,</span> <span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">a</span><span class="o">)</span> <span class="o">{</span> <span class="c">// first 2 may be Node instances or strings</span>
<span class="c"></span> <span class="nx">a</span> <span class="o">=</span> <span class="o">(</span><span class="nx">a</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">])</span> <span class="o">?</span> <span class="nx">a</span> <span class="o">:</span> <span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">a</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">b</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">b</span> <span class="o">=</span> <span class="o">(</span><span class="nx">b</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">])</span> <span class="o">?</span> <span class="nx">b</span> <span class="o">:</span> <span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">b</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span> <span class="o">&&</span> <span class="nx">METHODS_INVOKE</span><span class="o">[</span><span class="nx">method</span><span class="o">]</span> <span class="o">&&</span> <span class="nx">node</span><span class="o">[</span><span class="nx">method</span><span class="o">])</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">node</span><span class="o">[</span><span class="nx">method</span><span class="o">](</span><span class="nx">a</span><span class="o">,</span> <span class="nx">b</span><span class="o">,</span> <span class="nx">c</span><span class="o">,</span> <span class="nx">d</span><span class="o">,</span> <span class="nx">e</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">},</span>
<span class="nx">hasMethod</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">method</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="o">!!(</span><span class="nx">METHODS_INVOKE</span><span class="o">[</span><span class="nx">method</span><span class="o">]</span> <span class="o">&&</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">method</span><span class="o">]);</span>
<span class="o">},</span>
<span class="c">//normalize: function() {},</span>
<span class="c"></span> <span class="c">//isSupported: function(feature, version) {},</span>
<span class="c"></span> <span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">||</span> <span class="o">{};</span>
<span class="k">return</span> <span class="nx">node</span><span class="o">.</span><span class="nx">id</span> <span class="o">||</span> <span class="nx">node</span><span class="o">[</span><span class="nx">NODE_NAME</span><span class="o">]</span> <span class="o">||</span> <span class="s1">'undefined node'</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves a single node based on the given CSS selector. </span>
<span class="c"> * @method query</span>
<span class="c"> *</span>
<span class="c"> * @param {string} selector The CSS selector to test against.</span>
<span class="c"> * @return {Node} A Node instance for the matching HTMLElement.</span>
<span class="c"> */</span>
<span class="nx">query</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="kc">true</span><span class="o">));</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves a nodeList based on the given CSS selector. </span>
<span class="c"> * @method queryAll</span>
<span class="c"> *</span>
<span class="c"> * @param {string} selector The CSS selector to test against.</span>
<span class="c"> * @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.</span>
<span class="c"> */</span>
<span class="nx">queryAll</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span><span class="o">(</span><span class="nx">selector</span><span class="o">,</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]));</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Test if the supplied node matches the supplied selector.</span>
<span class="c"> * @method test</span>
<span class="c"> *</span>
<span class="c"> * @param {string} selector The CSS selector to test against.</span>
<span class="c"> * @return {boolean} Whether or not the node matches the selector.</span>
<span class="c"> */</span>
<span class="nx">test</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">test</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">selector</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves a style attribute from the given node.</span>
<span class="c"> * @method getStyle</span>
<span class="c"> * @param {String} attr The style attribute to retrieve. </span>
<span class="c"> * @return {String} The current value of the style property for the element.</span>
<span class="c"> */</span>
<span class="nx">getStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">attr</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">getStyle</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">attr</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Retrieves the computed value for the given style attribute.</span>
<span class="c"> * @method getComputedStyle</span>
<span class="c"> * @param {String} attr The style attribute to retrieve. </span>
<span class="c"> * @return {String} The computed value of the style property for the element.</span>
<span class="c"> */</span>
<span class="nx">getComputedStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">attr</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">getComputedStyle</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">attr</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Applies a CSS style to a given node.</span>
<span class="c"> * @method setStyle</span>
<span class="c"> * @param {String} attr The style attribute to set. </span>
<span class="c"> * @param {String|Number} val The value. </span>
<span class="c"> */</span>
<span class="nx">setStyle</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">attr</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">setStyle</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">attr</span><span class="o">,</span> <span class="nx">val</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Sets multiple style properties.</span>
<span class="c"> * @method setStyles</span>
<span class="c"> * @param {Object} hash An object literal of property:value pairs. </span>
<span class="c"> */</span>
<span class="nx">setStyles</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">hash</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">hash</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">n</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="nx">setStyle</span><span class="o">(</span><span class="nx">n</span><span class="o">,</span> <span class="nx">v</span><span class="o">);</span>
<span class="o">},</span> <span class="k">this</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Compares nodes to determine if they match.</span>
<span class="c"> * Node instances can be compared to each other and/or HTMLElements/selectors.</span>
<span class="c"> * @method compareTo</span>
<span class="c"> * @param {String | HTMLElement | Node} refNode The reference node to compare to the node.</span>
<span class="c"> * @return {Boolean} True if the nodes match, false if they do not. </span>
<span class="c"> */</span>
<span class="nx">compareTo</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">refNode</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">refNode</span> <span class="o">=</span> <span class="nx">refNode</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">]</span> <span class="o">?</span> <span class="nx">refNode</span> <span class="o">:</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">refNode</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">return</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">===</span> <span class="nx">refNode</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/*</span>
<span class="c"> * Returns the nearest ancestor that passes the test applied by supplied boolean method.</span>
<span class="c"> * @method ancestor</span>
<span class="c"> * @param {Function} fn - A boolean method for testing elements which receives the element as its only argument.</span>
<span class="c"> * @return {Node} The matching Node instance or null if not found</span>
<span class="c"> */</span>
<span class="nx">ancestor</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">elementByAxis</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">PARENT_NODE</span><span class="o">,</span> <span class="nx">wrapFn</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)));</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the previous sibling that is an HTMLElement. </span>
<span class="c"> * Returns the nearest HTMLElement sibling if no method provided.</span>
<span class="c"> * @method previous</span>
<span class="c"> * @param {Function} fn A boolean function used to test siblings</span>
<span class="c"> * that receives the sibling node being tested as its only argument.</span>
<span class="c"> * @param {Boolean} all optional Whether all node types should be returned, or just element nodes.</span>
<span class="c"> * @return {Node} Node instance or null if not found</span>
<span class="c"> */</span>
<span class="nx">previous</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">all</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">elementByAxis</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">PREVIOUS_SIBLING</span><span class="o">,</span> <span class="nx">wrapFn</span><span class="o">(</span><span class="nx">fn</span><span class="o">)),</span> <span class="nx">all</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the next sibling that passes the boolean method. </span>
<span class="c"> * Returns the nearest HTMLElement sibling if no method provided.</span>
<span class="c"> * @method next</span>
<span class="c"> * @param {Function} fn A boolean function used to test siblings</span>
<span class="c"> * that receives the sibling node being tested as its only argument.</span>
<span class="c"> * @param {Boolean} all optional Whether all node types should be returned, or just element nodes.</span>
<span class="c"> * @return {Object} HTMLElement or null if not found</span>
<span class="c"> */</span>
<span class="nx">next</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">all</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">elementByAxis</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">NEXT_SIBLING</span><span class="o">,</span> <span class="nx">wrapFn</span><span class="o">(</span><span class="nx">fn</span><span class="o">)),</span> <span class="nx">all</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Attaches a DOM event handler.</span>
<span class="c"> * @method attach</span>
<span class="c"> * @param {String} type The type of DOM Event to listen for </span>
<span class="c"> * @param {Function} fn The handler to call when the event fires </span>
<span class="c"> * @param {Object} arg An argument object to pass to the handler </span>
<span class="c"> */</span>
<span class="nx">attach</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">arg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">0</span><span class="o">);</span>
<span class="nx">args</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">addListener</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Alias for attach.</span>
<span class="c"> * @method on</span>
<span class="c"> * @param {String} type The type of DOM Event to listen for </span>
<span class="c"> * @param {Function} fn The handler to call when the event fires </span>
<span class="c"> * @param {Object} arg An argument object to pass to the handler </span>
<span class="c"> * @see attach</span>
<span class="c"> */</span>
<span class="nx">on</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">arg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">this</span><span class="o">.</span><span class="nx">attach</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="nx">arguments</span><span class="o">);</span>
<span class="o">},</span>
<span class="nx">addEventListener</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">arg</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">nativeAdd</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">,</span> <span class="nx">arg</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Detaches a DOM event handler. </span>
<span class="c"> * @method detach</span>
<span class="c"> * @param {String} type The type of DOM Event</span>
<span class="c"> * @param {Function} fn The handler to call when the event fires </span>
<span class="c"> */</span>
<span class="nx">detach</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">,</span> <span class="m">0</span><span class="o">);</span>
<span class="nx">args</span><span class="o">.</span><span class="nx">unshift</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]);</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">removeListener</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">,</span> <span class="nx">args</span><span class="o">);</span>
<span class="o">},</span>
<span class="nx">removeEventListener</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Event</span><span class="o">.</span><span class="nx">nativeRemove</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">type</span><span class="o">,</span> <span class="nx">fn</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Creates a Node instance from HTML string</span>
<span class="c"> * @method create</span>
<span class="c"> * @param {String|Array} html The string of html to create</span>
<span class="c"> * @return {Node} A new Node instance </span>
<span class="c"> */</span>
<span class="nx">create</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">html</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">create</span><span class="o">(</span><span class="nx">html</span><span class="o">);</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Determines whether an HTMLElement is an ancestor of another HTML element in the DOM hierarchy.</span>
<span class="c"> * @method contains</span>
<span class="c"> * @param {String | HTMLElement} needle The possible descendent</span>
<span class="c"> * @return {Boolean} Whether or not this node is an ancestor of needle</span>
<span class="c"> */</span>
<span class="nx">contains</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">needle</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">contains</span><span class="o">(</span><span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">getDOMNode</span><span class="o">(</span><span class="nx">needle</span><span class="o">));</span>
<span class="o">},</span>
<span class="nx">plug</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">PluginClass</span><span class="o">,</span> <span class="nx">config</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">config</span> <span class="o">=</span> <span class="nx">config</span> <span class="o">||</span> <span class="o">{};</span>
<span class="nx">config</span><span class="o">.</span><span class="nx">owner</span> <span class="o">=</span> <span class="k">this</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">PluginClass</span> <span class="o">&&</span> <span class="nx">PluginClass</span><span class="o">.</span><span class="nx">NS</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">[</span><span class="nx">PluginClass</span><span class="o">.</span><span class="nx">NS</span><span class="o">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PluginClass</span><span class="o">(</span><span class="nx">config</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Determines whether an HTMLElement is attached to a document.</span>
<span class="c"> * @method inDoc</span>
<span class="c"> * @param {Node|HTMLElement} doc optional An optional document to check against.</span>
<span class="c"> * Defaults to current document. </span>
<span class="c"> * @return {Boolean} Whether or not this node is attached to the document. </span>
<span class="c"> */</span>
<span class="nx">inDoc</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">doc</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="o">(</span><span class="nx">doc</span><span class="o">)</span> <span class="o">?</span> <span class="nx">getDoc</span><span class="o">(</span><span class="nx">doc</span><span class="o">)</span> <span class="o">:</span> <span class="nx">node</span><span class="o">.</span><span class="nx">ownerDocument</span><span class="o">;</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">doc</span><span class="o">.</span><span class="nx">documentElement</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">contains</span><span class="o">(</span><span class="nx">doc</span><span class="o">.</span><span class="nx">documentElement</span><span class="o">,</span> <span class="nx">node</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">METHODS</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">method</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">method</span><span class="o">]</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">fn</span><span class="o">.</span><span class="nx">apply</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="o">[</span><span class="nx">method</span><span class="o">].</span><span class="nx">concat</span><span class="o">(</span><span class="nx">slice</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">arguments</span><span class="o">)));</span>
<span class="o">};</span>
<span class="o">});</span>
<span class="c">/** </span>
<span class="c"> * Creates a Node instance from an HTML string</span>
<span class="c"> * @method create</span>
<span class="c"> * @param {String | Array} html HTML string</span>
<span class="c"> */</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">create</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">html</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">create</span><span class="o">(</span><span class="nx">html</span><span class="o">));</span>
<span class="o">};</span>
<span class="c">/** </span>
<span class="c"> * Returns a node instance wrapping the DOM element with the given ID. </span>
<span class="c"> * @method getById</span>
<span class="c"> * @static</span>
<span class="c"> * @param {String} id The ID to retrieve </span>
<span class="c"> * @param {Node|HTMLElement} doc optional An optional document to search. </span>
<span class="c"> * Defaults to current document.</span>
<span class="c"> */</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">getById</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">id</span><span class="o">,</span> <span class="nx">doc</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="o">(</span><span class="nx">doc</span> <span class="o">&&</span> <span class="nx">doc</span><span class="o">[</span><span class="nx">NODE_TYPE</span><span class="o">])</span> <span class="o">?</span> <span class="nx">doc</span> <span class="o">:</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">doc</span><span class="o">;</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">doc</span><span class="o">.</span><span class="nx">getElementById</span><span class="o">(</span><span class="nx">id</span><span class="o">));</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * Note: Use 'document' string to retrieve document Node instance from string</span>
<span class="c"> * @method get</span>
<span class="c"> * @static</span>
<span class="c"> * @param {document|HTMLElement|HTMLCollection|Array|String} node The object to wrap.</span>
<span class="c"> * @param {document|Node} doc optional The document containing the node. Defaults to current document.</span>
<span class="c"> * @param {boolean} isRoot optional Whether or not this node should be treated as a root node. Root nodes</span>
<span class="c"> * aren't allowed to traverse outside their DOM tree.</span>
<span class="c"> * @return {Node} A wrapper instance for the supplied object.</span>
<span class="c"> */</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">get</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">doc</span><span class="o">,</span> <span class="nx">isRoot</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">Node</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">node</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">doc</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">doc</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">&&</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">])</span> <span class="o">{</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node</span> <span class="o">&&</span> <span class="k">typeof</span> <span class="nx">node</span> <span class="o">===</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">switch</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">case</span> <span class="s1">'document'</span><span class="o">:</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">doc</span><span class="o">;</span>
<span class="k">break</span><span class="o">;</span>
<span class="nx">default</span><span class="o">:</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span><span class="o">(</span><span class="nx">node</span><span class="o">,</span> <span class="nx">doc</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="nx">node</span> <span class="o">=</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">node</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">isRoot</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_restrict</span> <span class="o">=</span> <span class="nx">_restrict</span> <span class="o">||</span> <span class="o">{};</span>
<span class="nx">_restrict</span><span class="o">[</span><span class="nx">node</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">=</span> <span class="nx">node</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">node</span><span class="o">;</span>
<span class="o">};</span>
<span class="c">/**</span>
<span class="c"> * @method all</span>
<span class="c"> * @static</span>
<span class="c"> * @param {HTMLCollection|Array|String} node The object to wrap.</span>
<span class="c"> * @param {document|Node} doc optional The document containing the node. Defaults to current document.</span>
<span class="c"> * @return {NodeList} A wrapper instance for the supplied nodes.</span>
<span class="c"> */</span>
<span class="nx">Node</span><span class="o">.</span><span class="nx">all</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">nodes</span><span class="o">,</span> <span class="nx">doc</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">nodes</span> <span class="k">instanceof</span> <span class="nx">NodeList</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">nodes</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(!</span><span class="nx">doc</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">config</span><span class="o">.</span><span class="nx">doc</span><span class="o">;</span>
<span class="o">}</span> <span class="k">else</span> <span class="k">if</span> <span class="o">(</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span> <span class="o">&&</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">])</span> <span class="o">{</span>
<span class="nx">doc</span> <span class="o">=</span> <span class="nx">_nodes</span><span class="o">[</span><span class="nx">doc</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="o">}</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">nodes</span> <span class="o">&&</span> <span class="k">typeof</span> <span class="nx">nodes</span> <span class="o">==</span> <span class="s1">'string'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">nodes</span> <span class="o">=</span> <span class="nx">Selector</span><span class="o">.</span><span class="nx">query</span><span class="o">(</span><span class="nx">nodes</span><span class="o">,</span> <span class="nx">doc</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">nodes</span><span class="o">);</span>
<span class="o">};</span>
<span class="c">/** </span>
<span class="c"> * A wrapper for manipulating multiple DOM elements</span>
<span class="c"> * @class NodeList</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">NodeList</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">nodes</span><span class="o">)</span> <span class="o">{</span>
<span class="c">// TODO: input validation</span>
<span class="c"></span> <span class="nx">_nodelists</span><span class="o">[</span><span class="nx">Y</span><span class="o">.</span><span class="nx">stamp</span><span class="o">(</span><span class="k">this</span><span class="o">)]</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">;</span>
<span class="o">};</span>
<span class="c">// used to call Node methods against NodeList nodes</span>
<span class="c"></span> <span class="k">var</span> <span class="nx">_tmpNode</span> <span class="o">=</span> <span class="nx">Node</span><span class="o">.</span><span class="nx">create</span><span class="o">(</span><span class="s1">'<div></div>'</span><span class="o">);</span>
<span class="nx">NodeList</span><span class="o">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="o">{};</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">typeof</span> <span class="nx">Node</span><span class="o">.</span><span class="nx">prototype</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">==</span> <span class="s1">'function'</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">addNodeListMethod</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">});</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">mix</span><span class="o">(</span><span class="nx">NodeList</span><span class="o">.</span><span class="nx">prototype</span><span class="o">,</span> <span class="o">{</span>
<span class="c">/**</span>
<span class="c"> * Retrieves the Node instance at the given index. </span>
<span class="c"> * @method item</span>
<span class="c"> *</span>
<span class="c"> * @param {Number} index The index of the target Node.</span>
<span class="c"> * @return {Node} The Node instance at the given index.</span>
<span class="c"> */</span>
<span class="nx">item</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">index</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">node</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">][</span><span class="nx">index</span><span class="o">];</span>
<span class="k">return</span> <span class="o">(</span><span class="nx">node</span> <span class="o">&&</span> <span class="nx">node</span><span class="o">[</span><span class="nx">TAG_NAME</span><span class="o">])</span> <span class="o">?</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">node</span><span class="o">)</span> <span class="o">:</span> <span class="o">(</span><span class="nx">node</span> <span class="o">&&</span> <span class="nx">node</span><span class="o">.</span><span class="nx">get</span><span class="o">)</span> <span class="o">?</span> <span class="nx">node</span> <span class="o">:</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Set the value of the property/attribute on all HTMLElements bound to this NodeList.</span>
<span class="c"> * @method set</span>
<span class="c"> * @param {String} prop Property to set </span>
<span class="c"> * @param {any} val Value to apply to the given property</span>
<span class="c"> * @see Node</span>
<span class="c"> */</span>
<span class="nx">set</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">val</span><span class="o">)</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_nodes</span><span class="o">[</span><span class="nx">_tmpNode</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="nx">_tmpNode</span><span class="o">.</span><span class="nx">set</span><span class="o">(</span><span class="nx">name</span><span class="o">,</span> <span class="nx">val</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Get the value of the property/attribute for each of the HTMLElements bound to this NodeList.</span>
<span class="c"> * @method get</span>
<span class="c"> * @param {String} prop Property to get </span>
<span class="c"> * @return {Array} Array containing the current values mapped to the Node indexes </span>
<span class="c"> * @see Node</span>
<span class="c"> */</span>
<span class="nx">get</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">name</span> <span class="o">==</span> <span class="s1">'length'</span><span class="o">)</span> <span class="o">{</span> <span class="c">// TODO: remove</span>
<span class="c"></span> <span class="nx">Y</span><span class="o">.</span><span class="nx">log</span><span class="o">(</span><span class="s1">'the length property is deprecated; use size()'</span><span class="o">,</span> <span class="s1">'warn'</span><span class="o">,</span> <span class="s1">'NodeList'</span><span class="o">);</span>
<span class="k">return</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">].</span><span class="nx">length</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">var</span> <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="o">[];</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">_nodes</span><span class="o">[</span><span class="nx">_tmpNode</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">[</span><span class="nx">i</span><span class="o">];</span>
<span class="nx">ret</span><span class="o">[</span><span class="nx">i</span><span class="o">]</span> <span class="o">=</span> <span class="nx">_tmpNode</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">name</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">ret</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Filters the NodeList instance down to only nodes matching the given selector.</span>
<span class="c"> * @method filter</span>
<span class="c"> * @param {String} selector The selector to filter against</span>
<span class="c"> * @return {NodeList} NodeList containing the updated collection </span>
<span class="c"> * @see Selector</span>
<span class="c"> */</span>
<span class="nx">filter</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">selector</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">wrapDOM</span><span class="o">(</span><span class="nx">Selector</span><span class="o">.</span><span class="nx">filter</span><span class="o">(</span><span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">],</span> <span class="nx">selector</span><span class="o">));</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Applies the given function to each Node in the NodeList.</span>
<span class="c"> * @method each</span>
<span class="c"> * @param {Function} fn The function to apply </span>
<span class="c"> * @param {Object} context optional An optional context to apply the function with</span>
<span class="c"> * Default context is the NodeList instance</span>
<span class="c"> * @return {NodeList} NodeList containing the updated collection </span>
<span class="c"> */</span>
<span class="nx">each</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">fn</span><span class="o">,</span> <span class="nx">context</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">context</span> <span class="o">=</span> <span class="nx">context</span> <span class="o">||</span> <span class="k">this</span><span class="o">;</span>
<span class="k">var</span> <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">];</span>
<span class="k">for</span> <span class="o">(</span><span class="k">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="m">0</span><span class="o">,</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">len</span><span class="o">;</span> <span class="o">++</span><span class="nx">i</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">fn</span><span class="o">.</span><span class="nx">call</span><span class="o">(</span><span class="nx">context</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">get</span><span class="o">(</span><span class="nx">nodes</span><span class="o">[</span><span class="nx">i</span><span class="o">]),</span> <span class="nx">i</span><span class="o">,</span> <span class="k">this</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">},</span>
<span class="c">/**</span>
<span class="c"> * Returns the current number of items in the NodeList.</span>
<span class="c"> * @method size</span>
<span class="c"> * @return {Int} The number of items in the NodeList. </span>
<span class="c"> */</span>
<span class="nx">size</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">].</span><span class="nx">length</span><span class="o">;</span>
<span class="o">},</span>
<span class="nx">toString</span><span class="o">:</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
<span class="k">var</span> <span class="nx">nodes</span> <span class="o">=</span> <span class="nx">_nodelists</span><span class="o">[</span><span class="k">this</span><span class="o">.</span><span class="nx">_yuid</span><span class="o">]</span> <span class="o">||</span> <span class="o">[];</span>
<span class="k">return</span> <span class="s1">'NodeList ('</span> <span class="o">+</span> <span class="nx">nodes</span><span class="o">.</span><span class="nx">length</span> <span class="o">+</span> <span class="s1">' items)'</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">},</span> <span class="kc">true</span><span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span> <span class="o">=</span> <span class="nx">Node</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">NodeList</span> <span class="o">=</span> <span class="nx">NodeList</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">all</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">all</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">get</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">get</span><span class="o">;</span>
<span class="c">/**</span>
<span class="c"> * Extended Node interface for managing classNames.</span>
<span class="c"> * @module node-class</span>
<span class="c"> */</span>
<span class="c">/**</span>
<span class="c"> * An interface for manipulating className strings.</span>
<span class="c"> * @interface NodeClassName</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">addDOMMethods</span><span class="o">([</span>
<span class="c">/**</span>
<span class="c"> * Determines whether an HTMLElement has the given className.</span>
<span class="c"> * @method hasClass</span>
<span class="c"> * @param {String} className the class name to search for</span>
<span class="c"> * @return {Boolean} A boolean value or array of boolean values</span>
<span class="c"> */</span>
<span class="s1">'hasClass'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Adds a class name to a given element or collection of elements.</span>
<span class="c"> * @method addClass </span>
<span class="c"> * @param {String} className the class name to add to the class attribute</span>
<span class="c"> */</span>
<span class="s1">'addClass'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Removes a class name from a given element or collection of elements.</span>
<span class="c"> * @method removeClass </span>
<span class="c"> * @param {String} className the class name to remove from the class attribute</span>
<span class="c"> */</span>
<span class="s1">'removeClass'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Replace a class with another class for a given element or collection of elements.</span>
<span class="c"> * If no oldClassName is present, the newClassName is simply added.</span>
<span class="c"> * @method replaceClass </span>
<span class="c"> * @param {String} oldClassName the class name to be replaced</span>
<span class="c"> * @param {String} newClassName the class name that will be replacing the old class name</span>
<span class="c"> */</span>
<span class="s1">'replaceClass'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * If the className exists on the node it is removed, if it doesn't exist it is added.</span>
<span class="c"> * @method toggleClass </span>
<span class="c"> * @param {String} className the class name to be toggled</span>
<span class="c"> */</span>
<span class="s1">'toggleClass'</span>
<span class="o">]);</span>
<span class="c">/**</span>
<span class="c"> * This module applies adds support for positioning elements and</span>
<span class="c"> * normalizes window size and scroll detection. </span>
<span class="c"> * @module node-screen</span>
<span class="c"> */</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">([</span>
<span class="s1">'winWidth'</span><span class="o">,</span>
<span class="s1">'winHeight'</span><span class="o">,</span>
<span class="s1">'docWidth'</span><span class="o">,</span>
<span class="s1">'docHeight'</span><span class="o">,</span>
<span class="s1">'docScrollX'</span><span class="o">,</span>
<span class="s1">'docScrollY'</span>
<span class="o">],</span>
<span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">n</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">getters</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">wrapDOMMethod</span><span class="o">(</span><span class="nx">v</span><span class="o">));</span>
<span class="o">}</span>
<span class="o">);</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">addDOMMethods</span><span class="o">([</span>
<span class="c">/**</span>
<span class="c"> * Gets the current position of the node in page coordinates. </span>
<span class="c"> * Nodes must be part of the DOM tree to have page coordinates</span>
<span class="c"> * (display:none or nodes not appended return false).</span>
<span class="c"> * @method getXY</span>
<span class="c"> * @return {Array} The XY position of the node</span>
<span class="c"> */</span>
<span class="s1">'getXY'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Set the position of a node in page coordinates, regardless of how the node is positioned.</span>
<span class="c"> * The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).</span>
<span class="c"> * @method setXY</span>
<span class="c"> * @param {Array} xy Contains X & Y values for new position (coordinates are page-based)</span>
<span class="c"> */</span>
<span class="s1">'setXY'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Gets the current position of the node in page coordinates. </span>
<span class="c"> * Nodes must be part of the DOM tree to have page coordinates</span>
<span class="c"> * (display:none or nodes not appended return false).</span>
<span class="c"> * @method getX</span>
<span class="c"> * @return {Int} The X position of the node</span>
<span class="c"> */</span>
<span class="s1">'getX'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Set the position of a node in page coordinates, regardless of how the node is positioned.</span>
<span class="c"> * The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).</span>
<span class="c"> * @method setX</span>
<span class="c"> * @param {Int} x X value for new position (coordinates are page-based)</span>
<span class="c"> */</span>
<span class="s1">'setX'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Gets the current position of the node in page coordinates. </span>
<span class="c"> * Nodes must be part of the DOM tree to have page coordinates</span>
<span class="c"> * (display:none or nodes not appended return false).</span>
<span class="c"> * @method getY</span>
<span class="c"> * @return {Int} The Y position of the node</span>
<span class="c"> */</span>
<span class="s1">'getY'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Set the position of a node in page coordinates, regardless of how the node is positioned.</span>
<span class="c"> * The node must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).</span>
<span class="c"> * @method setY</span>
<span class="c"> * @param {Int} y Y value for new position (coordinates are page-based)</span>
<span class="c"> */</span>
<span class="s1">'setY'</span>
<span class="o">]);</span>
<span class="c">/**</span>
<span class="c"> * Extended Node interface for managing regions.</span>
<span class="c"> * @module node-region</span>
<span class="c"> */</span>
<span class="k">var</span> <span class="nx">ATTR</span> <span class="o">=</span> <span class="o">[</span><span class="s1">'region'</span><span class="o">,</span> <span class="s1">'viewportRegion'</span><span class="o">],</span>
<span class="nx">getNode</span> <span class="o">=</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">getDOMNode</span><span class="o">;</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">each</span><span class="o">(</span><span class="nx">ATTR</span><span class="o">,</span> <span class="k">function</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">n</span><span class="o">)</span> <span class="o">{</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">getters</span><span class="o">(</span><span class="nx">v</span><span class="o">,</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">wrapDOMMethod</span><span class="o">(</span><span class="nx">v</span><span class="o">));</span>
<span class="o">});</span>
<span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">addDOMMethods</span><span class="o">([</span>
<span class="s1">'inViewportRegion'</span>
<span class="o">]);</span>
<span class="c">// these need special treatment to extract 2nd node arg</span>
<span class="c"></span><span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">.</span><span class="nx">methods</span><span class="o">({</span>
<span class="nx">intersect</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node1</span><span class="o">,</span> <span class="nx">node2</span><span class="o">,</span> <span class="nx">altRegion</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node2</span> <span class="k">instanceof</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">)</span> <span class="o">{</span> <span class="c">// might be a region object</span>
<span class="c"></span> <span class="nx">node2</span> <span class="o">=</span> <span class="nx">getNode</span><span class="o">(</span><span class="nx">node2</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">intersect</span><span class="o">(</span><span class="nx">getNode</span><span class="o">(</span><span class="nx">node1</span><span class="o">),</span> <span class="nx">node2</span><span class="o">,</span> <span class="nx">altRegion</span><span class="o">);</span>
<span class="o">},</span>
<span class="nx">inRegion</span><span class="o">:</span> <span class="k">function</span><span class="o">(</span><span class="nx">node1</span><span class="o">,</span> <span class="nx">node2</span><span class="o">,</span> <span class="nx">all</span><span class="o">,</span> <span class="nx">altRegion</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="nx">node2</span> <span class="k">instanceof</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">Node</span><span class="o">)</span> <span class="o">{</span> <span class="c">// might be a region object</span>
<span class="c"></span> <span class="nx">node2</span> <span class="o">=</span> <span class="nx">getNode</span><span class="o">(</span><span class="nx">node2</span><span class="o">);</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nx">Y</span><span class="o">.</span><span class="nx">DOM</span><span class="o">.</span><span class="nx">inRegion</span><span class="o">(</span><span class="nx">getNode</span><span class="o">(</span><span class="nx">node1</span><span class="o">),</span> <span class="nx">node2</span><span class="o">,</span> <span class="nx">all</span><span class="o">,</span> <span class="nx">altRegion</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">});</span>
<span class="o">},</span> <span class="s1">'@VERSION@'</span> <span class="o">,{</span><span class="nx">requires</span><span class="o">:[</span><span class="s1">'dom'</span><span class="o">]});</span>
</pre></div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright © 2008 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>