Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / Element.position-more.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">/**\r
9  * @class Ext.Element\r
10  */\r
11 Ext.Element.addMethods({\r
12     <div id="method-Ext.Element-setBox"></div>/**\r
13      * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.\r
14      * @param {Object} box The box to fill {x, y, width, height}\r
15      * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically\r
16      * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object\r
17      * @return {Ext.Element} this\r
18      */\r
19     setBox : function(box, adjust, animate){\r
20         var me = this,\r
21                 w = box.width, \r
22                 h = box.height;\r
23         if((adjust && !me.autoBoxAdjust) && !me.isBorderBox()){\r
24            w -= (me.getBorderWidth("lr") + me.getPadding("lr"));\r
25            h -= (me.getBorderWidth("tb") + me.getPadding("tb"));\r
26         }\r
27         me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));\r
28         return me;\r
29     },\r
30     \r
31     <div id="method-Ext.Element-getBox"></div>/**\r
32      * Return a box {x, y, width, height} that can be used to set another elements\r
33      * size/location to match this element.\r
34      * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.\r
35      * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.\r
36      * @return {Object} box An object in the format {x, y, width, height}\r
37      */\r
38         getBox : function(contentBox, local) {      \r
39             var me = this,\r
40                 xy,\r
41                 left,\r
42                 top,\r
43                 getBorderWidth = me.getBorderWidth,\r
44                 getPadding = me.getPadding, \r
45                 l,\r
46                 r,\r
47                 t,\r
48                 b;\r
49         if(!local){\r
50             xy = me.getXY();\r
51         }else{\r
52             left = parseInt(me.getStyle("left"), 10) || 0;\r
53             top = parseInt(me.getStyle("top"), 10) || 0;\r
54             xy = [left, top];\r
55         }\r
56         var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;\r
57         if(!contentBox){\r
58             bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};\r
59         }else{\r
60             l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");\r
61             r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");\r
62             t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");\r
63             b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");\r
64             bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};\r
65         }\r
66         bx.right = bx.x + bx.width;\r
67         bx.bottom = bx.y + bx.height;\r
68         return bx;\r
69         },\r
70         \r
71     <div id="method-Ext.Element-move"></div>/**\r
72      * Move this element relative to its current position.\r
73      * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").\r
74      * @param {Number} distance How far to move the element in pixels\r
75      * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object\r
76      * @return {Ext.Element} this\r
77      */\r
78      move : function(direction, distance, animate){\r
79         var me = this,          \r
80                 xy = me.getXY(),\r
81                 x = xy[0],\r
82                 y = xy[1],              \r
83                 left = [x - distance, y],\r
84                 right = [x + distance, y],\r
85                 top = [x, y - distance],\r
86                 bottom = [x, y + distance],\r
87                 hash = {\r
88                         l :     left,\r
89                         left : left,\r
90                         r : right,\r
91                         right : right,\r
92                         t : top,\r
93                         top : top,\r
94                         up : top,\r
95                         b : bottom, \r
96                         bottom : bottom,\r
97                         down : bottom                           \r
98                 };\r
99         \r
100             direction = direction.toLowerCase();    \r
101             me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));\r
102     },\r
103     \r
104     <div id="method-Ext.Element-setLeftTop"></div>/**\r
105      * Quick set left and top adding default units\r
106      * @param {String} left The left CSS property value\r
107      * @param {String} top The top CSS property value\r
108      * @return {Ext.Element} this\r
109      */\r
110      setLeftTop : function(left, top){\r
111             var me = this,\r
112                 style = me.dom.style;\r
113         style.left = me.addUnits(left);\r
114         style.top = me.addUnits(top);\r
115         return me;\r
116     },\r
117     \r
118     <div id="method-Ext.Element-getRegion"></div>/**\r
119      * Returns the region of the given element.\r
120      * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).\r
121      * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data.\r
122      */\r
123     getRegion : function(){\r
124         return Ext.lib.Dom.getRegion(this.dom);\r
125     },\r
126     \r
127     <div id="method-Ext.Element-setBounds"></div>/**\r
128      * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.\r
129      * @param {Number} x X value for new position (coordinates are page-based)\r
130      * @param {Number} y Y value for new position (coordinates are page-based)\r
131      * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>\r
132      * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>\r
133      * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.\r
134      * </ul></div>\r
135      * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>\r
136      * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>\r
137      * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>\r
138      * </ul></div>\r
139      * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object\r
140      * @return {Ext.Element} this\r
141      */\r
142     setBounds : function(x, y, width, height, animate){\r
143             var me = this;\r
144         if (!animate || !me.anim) {\r
145             me.setSize(width, height);\r
146             me.setLocation(x, y);\r
147         } else {\r
148             me.anim({points: {to: [x, y]}, \r
149                          width: {to: me.adjustWidth(width)}, \r
150                          height: {to: me.adjustHeight(height)}},\r
151                      me.preanim(arguments, 4), \r
152                      'motion');\r
153         }\r
154         return me;\r
155     },\r
156 \r
157     <div id="method-Ext.Element-setRegion"></div>/**\r
158      * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.\r
159      * @param {Ext.lib.Region} region The region to fill\r
160      * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object\r
161      * @return {Ext.Element} this\r
162      */\r
163     setRegion : function(region, animate) {\r
164         return this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.animTest.call(this, arguments, animate, 1));\r
165     }\r
166 });</pre>    \r
167 </body>\r
168 </html>