source: trunk/web/addons/job_monarch/lib/extjs-30/src/core/Element.position-more.js @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

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