webgui/www/extras/yui/docs/animation/overview-summary-Region.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

364 lines
10 KiB
HTML

<html>
<head>
<title>
JavaScript Documentation -
Region.js
</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>JavaScript Documentation</h1>
<h3><a href="./index.html">DOM Utility</a></h3>
<div class="breadcrumbs">
<a href="./index.html">DOM Utility</a>
&gt;
<strong>Region.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.util.Dom.html">
YAHOO.util.Dom</a>
</li>
<li>
<a href="YAHOO.util.Point.html">
YAHOO.util.Point</a>
</li>
<li>
<a href="YAHOO.util.Region.html">
YAHOO.util.Region</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-Dom.js.html">
Dom.js</a>
</li>
<li>
<a href="overview-summary-Region.js.html">
Region.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>Region.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#classSummary">Class Summary</a> |
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<h3><a name="classSummary">Class Summary</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<div class="content">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="name">
<a href="YAHOO.util.Point.html">YAHOO.util.Point</a>
</td>
<td class="overview">A point is a region that is special in that it represents a single point on
the grid.</td>
</tr>
<tr>
<td class="name">
<a href="YAHOO.util.Region.html">YAHOO.util.Region</a>
</td>
<td class="overview">A region is a representation of an object on a grid.</td>
</tr>
</table>
</div>
</div>
<div class="section source">
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview"><span class="comment">/**
* <span class="attrib">@class</span> A region is a representation of an object on a grid. It is defined
* by the top, right, bottom, left extents, so is rectangular by default. If
* other shapes are required, this class could be extended to support it.
*
* <span class="attrib">@param</span> {int} t the top extent
* <span class="attrib">@param</span> {int} r the right extent
* <span class="attrib">@param</span> {int} b the bottom extent
* <span class="attrib">@param</span> {int} l the left extent
* <span class="attrib">@constructor</span>
*/</span>
YAHOO.util.Region = <span class="reserved">function</span>(t, r, b, l) {
<span class="comment">/**
* The region's top extent
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.top = t;
<span class="comment">/**
* The region's right extent
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.right = r;
<span class="comment">/**
* The region's bottom extent
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.bottom = b;
<span class="comment">/**
* The region's left extent
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.left = l;
};
<span class="comment">/**
* Returns true if this region contains the region passed in
*
* <span class="attrib">@param</span> {Region} region The region to evaluate
* <span class="attrib">@return</span> {boolean} True if the region is contained with this region,
* else false
*/</span>
YAHOO.util.Region.<span class="reserved">prototype</span>.contains = <span class="reserved">function</span>(region) {
<span class="reserved">return</span> ( region.left &gt;= <span class="reserved">this</span>.left &amp;&amp;
region.right &lt;= <span class="reserved">this</span>.right &amp;&amp;
region.top &gt;= <span class="reserved">this</span>.top &amp;&amp;
region.bottom &lt;= <span class="reserved">this</span>.bottom );
<span class="comment">// this.logger.debug("does " + this + " contain " + region + " ... " + ret);</span>
};
<span class="comment">/**
* Returns the area of the region
*
* <span class="attrib">@return</span> {int} the region's area
*/</span>
YAHOO.util.Region.<span class="reserved">prototype</span>.getArea = <span class="reserved">function</span>() {
<span class="reserved">return</span> ( (<span class="reserved">this</span>.bottom - <span class="reserved">this</span>.top) * (<span class="reserved">this</span>.right - <span class="reserved">this</span>.left) );
};
<span class="comment">/**
* Returns the region where the passed in region overlaps with this one
*
* <span class="attrib">@param</span> {Region} region The region that intersects
* <span class="attrib">@return</span> {Region} The overlap region, or null if there is no overlap
*/</span>
YAHOO.util.Region.<span class="reserved">prototype</span>.intersect = <span class="reserved">function</span>(region) {
var t = Math.max( <span class="reserved">this</span>.top, region.top );
var r = Math.min( <span class="reserved">this</span>.right, region.right );
var b = Math.min( <span class="reserved">this</span>.bottom, region.bottom );
var l = Math.max( <span class="reserved">this</span>.left, region.left );
<span class="reserved">if</span> (b &gt;= t &amp;&amp; r &gt;= l) {
<span class="reserved">return</span> new YAHOO.util.Region(t, r, b, l);
} <span class="reserved">else</span> {
<span class="reserved">return</span> null;
}
};
<span class="comment">/**
* Returns the region representing the smallest region that can contain both
* the passed in region and this region.
*
* <span class="attrib">@param</span> {Region} region The region that to create the union with
* <span class="attrib">@return</span> {Region} The union region
*/</span>
YAHOO.util.Region.<span class="reserved">prototype</span>.union = <span class="reserved">function</span>(region) {
var t = Math.min( <span class="reserved">this</span>.top, region.top );
var r = Math.max( <span class="reserved">this</span>.right, region.right );
var b = Math.max( <span class="reserved">this</span>.bottom, region.bottom );
var l = Math.min( <span class="reserved">this</span>.left, region.left );
<span class="reserved">return</span> new YAHOO.util.Region(t, r, b, l);
};
<span class="comment">/**
* toString
* <span class="attrib">@return</span> string the region properties
*/</span>
YAHOO.util.Region.<span class="reserved">prototype</span>.toString = <span class="reserved">function</span>() {
<span class="reserved">return</span> ( <span class="literal">"Region {"</span> +
<span class="literal">" t: "</span> + <span class="reserved">this</span>.top +
<span class="literal">", r: "</span> + <span class="reserved">this</span>.right +
<span class="literal">", b: "</span> + <span class="reserved">this</span>.bottom +
<span class="literal">", l: "</span> + <span class="reserved">this</span>.left +
<span class="literal">"}"</span> );
}
<span class="comment">/**
* Returns a region that is occupied by the DOM element
*
* <span class="attrib">@param</span> {HTMLElement} el The element
* <span class="attrib">@return</span> {Region} The region that the element occupies
* <span class="attrib">@static</span>
*/</span>
YAHOO.util.Region.getRegion = <span class="reserved">function</span>(el) {
var p = YAHOO.util.Dom.getXY(el);
var t = p[1];
var r = p[0] + el.offsetWidth;
var b = p[1] + el.offsetHeight;
var l = p[0];
<span class="reserved">return</span> new YAHOO.util.Region(t, r, b, l);
};
<span class="comment">/////////////////////////////////////////////////////////////////////////////</span>
<span class="comment">/**
* <span class="attrib">@class</span>
*
* A point is a region that is special in that it represents a single point on
* the grid.
*
* <span class="attrib">@param</span> {int} x The X position of the point
* <span class="attrib">@param</span> {int} y The Y position of the point
* <span class="attrib">@constructor</span>
* <span class="attrib">@extends</span> Region
*/</span>
YAHOO.util.Point = <span class="reserved">function</span>(x, y) {
<span class="comment">/**
* The X position of the point
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.x = x;
<span class="comment">/**
* The Y position of the point
* <span class="attrib">@type</span> int
*/</span>
<span class="reserved">this</span>.y = y;
<span class="reserved">this</span>.top = y;
<span class="reserved">this</span>.right = x;
<span class="reserved">this</span>.bottom = y;
<span class="reserved">this</span>.left = x;
};
YAHOO.util.Point.<span class="reserved">prototype</span> = new YAHOO.util.Region();
</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2006 Yahoo! Inc. All rights reserved.
</div>
</body>
</html>