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>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
15 * @class Ext.Element
\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
25 setBox : function(box, adjust, animate){
\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
33 me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));
\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
44 getBox : function(contentBox, local) {
\r
49 getBorderWidth = me.getBorderWidth,
\r
50 getPadding = me.getPadding,
\r
58 left = parseInt(me.getStyle("left"), 10) || 0;
\r
59 top = parseInt(me.getStyle("top"), 10) || 0;
\r
62 var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
\r
64 bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
\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
72 bx.right = bx.x + bx.width;
\r
73 bx.bottom = bx.y + bx.height;
\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
84 move : function(direction, distance, animate){
\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
106 direction = direction.toLowerCase();
\r
107 me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));
\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
116 setLeftTop : function(left, top){
\r
118 style = me.dom.style;
\r
119 style.left = me.addUnits(left);
\r
120 style.top = me.addUnits(top);
\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
129 getRegion : function(){
\r
130 return Ext.lib.Dom.getRegion(this.dom);
\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
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
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
148 setBounds : function(x, y, width, height, animate){
\r
150 if (!animate || !me.anim) {
\r
151 me.setSize(width, height);
\r
152 me.setLocation(x, y);
\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
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
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