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