3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 Ext.Element.addMethods({
\r
12 * 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
13 * @param {Object} box The box to fill {x, y, width, height}
\r
14 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
\r
15 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
16 * @return {Ext.Element} this
\r
18 setBox : function(box, adjust, animate){
\r
22 if((adjust && !me.autoBoxAdjust) && !me.isBorderBox()){
\r
23 w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
\r
24 h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
\r
26 me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));
\r
31 * Return a box {x, y, width, height} that can be used to set another elements
\r
32 * size/location to match this element.
\r
33 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
\r
34 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
\r
35 * @return {Object} box An object in the format {x, y, width, height}
\r
37 getBox : function(contentBox, local) {
\r
42 getBorderWidth = me.getBorderWidth,
\r
43 getPadding = me.getPadding,
\r
51 left = parseInt(me.getStyle("left"), 10) || 0;
\r
52 top = parseInt(me.getStyle("top"), 10) || 0;
\r
55 var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
\r
57 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
\r
59 l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");
\r
60 r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");
\r
61 t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");
\r
62 b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");
\r
63 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 bx.right = bx.x + bx.width;
\r
66 bx.bottom = bx.y + bx.height;
\r
71 * Move this element relative to its current position.
\r
72 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
\r
73 * @param {Number} distance How far to move the element in pixels
\r
74 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
75 * @return {Ext.Element} this
\r
77 move : function(direction, distance, animate){
\r
82 left = [x - distance, y],
\r
83 right = [x + distance, y],
\r
84 top = [x, y - distance],
\r
85 bottom = [x, y + distance],
\r
99 direction = direction.toLowerCase();
\r
100 me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));
\r
104 * Quick set left and top adding default units
\r
105 * @param {String} left The left CSS property value
\r
106 * @param {String} top The top CSS property value
\r
107 * @return {Ext.Element} this
\r
109 setLeftTop : function(left, top){
\r
111 style = me.dom.style;
\r
112 style.left = me.addUnits(left);
\r
113 style.top = me.addUnits(top);
\r
118 * Returns the region of the given element.
\r
119 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
\r
120 * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data.
\r
122 getRegion : function(){
\r
123 return Ext.lib.Dom.getRegion(this.dom);
\r
127 * 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
128 * @param {Number} x X value for new position (coordinates are page-based)
\r
129 * @param {Number} y Y value for new position (coordinates are page-based)
\r
130 * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
\r
131 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>
\r
132 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
\r
134 * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
\r
135 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>
\r
136 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
\r
138 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
139 * @return {Ext.Element} this
\r
141 setBounds : function(x, y, width, height, animate){
\r
143 if (!animate || !me.anim) {
\r
144 me.setSize(width, height);
\r
145 me.setLocation(x, y);
\r
147 me.anim({points: {to: [x, y]},
\r
148 width: {to: me.adjustWidth(width)},
\r
149 height: {to: me.adjustHeight(height)}},
\r
150 me.preanim(arguments, 4),
\r
157 * 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
158 * @param {Ext.lib.Region} region The region to fill
\r
159 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
\r
160 * @return {Ext.Element} this
\r
162 setRegion : function(region, animate) {
\r
163 return this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.animTest.call(this, arguments, animate, 1));
\r