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