Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / ext-base-region.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">   Ext.lib.Region = function(t, r, b, l) {\r
9                 var me = this;\r
10         me.top = t;\r
11         me[1] = t;\r
12         me.right = r;\r
13         me.bottom = b;\r
14         me.left = l;\r
15         me[0] = l;\r
16     };\r
17 \r
18     Ext.lib.Region.prototype = {\r
19         contains : function(region) {\r
20                 var me = this;\r
21             return ( region.left >= me.left &&\r
22                      region.right <= me.right &&\r
23                      region.top >= me.top &&\r
24                      region.bottom <= me.bottom );\r
25 \r
26         },\r
27 \r
28         getArea : function() {\r
29                 var me = this;\r
30             return ( (me.bottom - me.top) * (me.right - me.left) );\r
31         },\r
32 \r
33         intersect : function(region) {\r
34             var me = this,\r
35                 t = Math.max(me.top, region.top),\r
36                 r = Math.min(me.right, region.right),\r
37                 b = Math.min(me.bottom, region.bottom),\r
38                 l = Math.max(me.left, region.left);\r
39 \r
40             if (b >= t && r >= l) {\r
41                 return new Ext.lib.Region(t, r, b, l);\r
42             }\r
43         },\r
44         \r
45         union : function(region) {\r
46                 var me = this,\r
47                 t = Math.min(me.top, region.top),\r
48                 r = Math.max(me.right, region.right),\r
49                 b = Math.max(me.bottom, region.bottom),\r
50                 l = Math.min(me.left, region.left);\r
51 \r
52             return new Ext.lib.Region(t, r, b, l);\r
53         },\r
54 \r
55         constrainTo : function(r) {\r
56                 var me = this;\r
57             me.top = me.top.constrain(r.top, r.bottom);\r
58             me.bottom = me.bottom.constrain(r.top, r.bottom);\r
59             me.left = me.left.constrain(r.left, r.right);\r
60             me.right = me.right.constrain(r.left, r.right);\r
61             return me;\r
62         },\r
63 \r
64         adjust : function(t, l, b, r) {\r
65                 var me = this;\r
66             me.top += t;\r
67             me.left += l;\r
68             me.right += r;\r
69             me.bottom += b;\r
70             return me;\r
71         }\r
72     };\r
73 \r
74     Ext.lib.Region.getRegion = function(el) {\r
75         var p = Ext.lib.Dom.getXY(el),\r
76                 t = p[1],\r
77                 r = p[0] + el.offsetWidth,\r
78                 b = p[1] + el.offsetHeight,\r
79                 l = p[0];\r
80 \r
81         return new Ext.lib.Region(t, r, b, l);\r
82     };</pre>    \r
83 </body>\r
84 </html>