node-region.js.html revision 4fcbec6145d16637205990699912fb90f6a3807c
<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-region.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" /> <label for="showprivate">Show Private</label></span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> <label for="showprotected">Show Protected</label></span>
<span id="classopts"><input type="checkbox" name="showdeprecated" id="showdeprecated" /> <label for="showdeprecated">Show Deprecated</label></span>
</form>
<div id="srcout">
<style>
#doc3 #classopts { display:none; }
</style>
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * Extended Node interface for managing regions and screen positioning.</span>
<span class="c"> * Adds support for positioning elements and normalizes window size and scroll detection. </span>
<span class="c"> * @module node</span>
<span class="c"> * @submodule node-screen</span>
<span class="c"> * @for Node</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="c">/**</span>
<span class="c"> * Returns a region object for the node </span>
<span class="c"> * @attribute region</span>
<span class="c"> * @type Node</span>
<span class="c"> */</span>
<span class="s1">'region'</span><span class="o">,</span>
<span class="c">/**</span>
<span class="c"> * Returns a region object for the node's viewport </span>
<span class="c"> * @attribute viewportRegion</span>
<span class="c"> * @type Node</span>
<span class="c"> */</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="c">/**</span>
<span class="c"> * Removes a class name from a given element or collection of elements.</span>
<span class="c"> * @method inViewportRegion </span>
<span class="c"> * @return {Boolean} Whether or not the node is currently positioned</span>
<span class="c"> * within the viewport's region</span>
<span class="c"> */</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="c">/**</span>
<span class="c"> * Compares the intersection of the node with another node or region </span>
<span class="c"> * @method intersect </span>
<span class="c"> * @param {Node|Object} node2 The node or region to compare with.</span>
<span class="c"> * @param {Object} altRegion An alternate region to use (rather than this node's). </span>
<span class="c"> * @return {Object} An object representing the intersection of the regions. </span>
<span class="c"> */</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="c">/**</span>
<span class="c"> * Determines whether or not the node is within the giving region.</span>
<span class="c"> * @method inRegion </span>
<span class="c"> * @param {Node|Object} node2 The node or region to compare with.</span>
<span class="c"> * @param {Boolean} all Whether or not all of the node must be in the region. </span>
<span class="c"> * @param {Object} altRegion An alternate region to use (rather than this node's). </span>
<span class="c"> * @return {Object} An object representing the intersection of the regions. </span>
<span class="c"> */</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>
</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>