3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">/**
\r
10 * @class Ext.Element
\r
13 var D = Ext.lib.Dom,
\r
18 POSITION = "position",
\r
20 RELATIVE = "relative",
\r
24 Ext.Element.addMethods({
\r
25 <div id="method-Ext.Element-getX"></div>/**
\r
26 * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
27 * @return {Number} The X position of the element
\r
30 return D.getX(this.dom);
\r
33 <div id="method-Ext.Element-getY"></div>/**
\r
34 * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
35 * @return {Number} The Y position of the element
\r
38 return D.getY(this.dom);
\r
41 <div id="method-Ext.Element-getXY"></div>/**
\r
42 * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
43 * @return {Array} The XY position of the element
\r
46 return D.getXY(this.dom);
\r
49 <div id="method-Ext.Element-getOffsetsTo"></div>/**
\r
50 * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
\r
51 * @param {Mixed} element The element to get the offsets from.
\r
52 * @return {Array} The XY page offsets (e.g. [100, -200])
\r
54 getOffsetsTo : function(el){
\r
55 var o = this.getXY(),
\r
56 e = Ext.fly(el, '_internal').getXY();
\r
57 return [o[0]-e[0],o[1]-e[1]];
\r
60 <div id="method-Ext.Element-setX"></div>/**
\r
61 * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
62 * @param {Number} The X position of the element
\r
63 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
64 * @return {Ext.Element} this
\r
66 setX : function(x, animate){
\r
67 return this.setXY([x, this.getY()], this.animTest(arguments, animate, 1));
\r
70 <div id="method-Ext.Element-setY"></div>/**
\r
71 * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
72 * @param {Number} The Y position of the element
\r
73 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
74 * @return {Ext.Element} this
\r
76 setY : function(y, animate){
\r
77 return this.setXY([this.getX(), y], this.animTest(arguments, animate, 1));
\r
80 <div id="method-Ext.Element-setLeft"></div>/**
\r
81 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
\r
82 * @param {String} left The left CSS property value
\r
83 * @return {Ext.Element} this
\r
85 setLeft : function(left){
\r
86 this.setStyle(LEFT, this.addUnits(left));
\r
90 <div id="method-Ext.Element-setTop"></div>/**
\r
91 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
\r
92 * @param {String} top The top CSS property value
\r
93 * @return {Ext.Element} this
\r
95 setTop : function(top){
\r
96 this.setStyle(TOP, this.addUnits(top));
\r
100 <div id="method-Ext.Element-setRight"></div>/**
\r
101 * Sets the element's CSS right style.
\r
102 * @param {String} right The right CSS property value
\r
103 * @return {Ext.Element} this
\r
105 setRight : function(right){
\r
106 this.setStyle(RIGHT, this.addUnits(right));
\r
110 <div id="method-Ext.Element-setBottom"></div>/**
\r
111 * Sets the element's CSS bottom style.
\r
112 * @param {String} bottom The bottom CSS property value
\r
113 * @return {Ext.Element} this
\r
115 setBottom : function(bottom){
\r
116 this.setStyle(BOTTOM, this.addUnits(bottom));
\r
120 <div id="method-Ext.Element-setXY"></div>/**
\r
121 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
122 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
123 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
\r
124 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
125 * @return {Ext.Element} this
\r
127 setXY : function(pos, animate){
\r
129 if(!animate || !me.anim){
\r
130 D.setXY(me.dom, pos);
\r
132 me.anim({points: {to: pos}}, me.preanim(arguments, 1), 'motion');
\r
137 <div id="method-Ext.Element-setLocation"></div>/**
\r
138 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
139 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
140 * @param {Number} x X value for new position (coordinates are page-based)
\r
141 * @param {Number} y Y value for new position (coordinates are page-based)
\r
142 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
143 * @return {Ext.Element} this
\r
145 setLocation : function(x, y, animate){
\r
146 return this.setXY([x, y], this.animTest(arguments, animate, 2));
\r
149 <div id="method-Ext.Element-moveTo"></div>/**
\r
150 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
151 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
152 * @param {Number} x X value for new position (coordinates are page-based)
\r
153 * @param {Number} y Y value for new position (coordinates are page-based)
\r
154 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
155 * @return {Ext.Element} this
\r
157 moveTo : function(x, y, animate){
\r
158 return this.setXY([x, y], this.animTest(arguments, animate, 2));
\r
161 <div id="method-Ext.Element-getLeft"></div>/**
\r
162 * Gets the left X coordinate
\r
163 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
166 getLeft : function(local){
\r
167 return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
\r
170 <div id="method-Ext.Element-getRight"></div>/**
\r
171 * Gets the right X coordinate of the element (element X position + element width)
\r
172 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
175 getRight : function(local){
\r
177 return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
\r
180 <div id="method-Ext.Element-getTop"></div>/**
\r
181 * Gets the top Y coordinate
\r
182 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
185 getTop : function(local) {
\r
186 return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
\r
189 <div id="method-Ext.Element-getBottom"></div>/**
\r
190 * Gets the bottom Y coordinate of the element (element Y position + element height)
\r
191 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
194 getBottom : function(local){
\r
196 return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
\r
199 <div id="method-Ext.Element-position"></div>/**
\r
200 * Initializes positioning on this element. If a desired position is not passed, it will make the
\r
201 * the element positioned relative IF it is not already positioned.
\r
202 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
\r
203 * @param {Number} zIndex (optional) The zIndex to apply
\r
204 * @param {Number} x (optional) Set the page X position
\r
205 * @param {Number} y (optional) Set the page Y position
\r
207 position : function(pos, zIndex, x, y){
\r
210 if(!pos && me.isStyle(POSITION, STATIC)){
\r
211 me.setStyle(POSITION, RELATIVE);
\r
213 me.setStyle(POSITION, pos);
\r
216 me.setStyle(ZINDEX, zIndex);
\r
218 if(x || y) me.setXY([x || false, y || false]);
\r
221 <div id="method-Ext.Element-clearPositioning"></div>/**
\r
222 * Clear positioning back to the default when the document was loaded
\r
223 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
\r
224 * @return {Ext.Element} this
\r
226 clearPositioning : function(value){
\r
227 value = value || '';
\r
239 <div id="method-Ext.Element-getPositioning"></div>/**
\r
240 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
\r
241 * snapshot before performing an update and then restoring the element.
\r
244 getPositioning : function(){
\r
245 var l = this.getStyle(LEFT);
\r
246 var t = this.getStyle(TOP);
\r
248 "position" : this.getStyle(POSITION),
\r
250 "right" : l ? "" : this.getStyle(RIGHT),
\r
252 "bottom" : t ? "" : this.getStyle(BOTTOM),
\r
253 "z-index" : this.getStyle(ZINDEX)
\r
257 <div id="method-Ext.Element-setPositioning"></div>/**
\r
258 * Set positioning with an object returned by getPositioning().
\r
259 * @param {Object} posCfg
\r
260 * @return {Ext.Element} this
\r
262 setPositioning : function(pc){
\r
264 style = me.dom.style;
\r
268 if(pc.right == AUTO){
\r
271 if(pc.bottom == AUTO){
\r
278 <div id="method-Ext.Element-translatePoints"></div>/**
\r
279 * Translates the passed page coordinates into left/top css values for this element
\r
280 * @param {Number/Array} x The page x or an array containing [x, y]
\r
281 * @param {Number} y (optional) The page y, required if x is not an array
\r
282 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
\r
284 translatePoints : function(x, y){
\r
285 y = isNaN(x[1]) ? y : x[1];
\r
286 x = isNaN(x[0]) ? x : x[0];
\r
288 relative = me.isStyle(POSITION, RELATIVE),
\r
290 l = parseInt(me.getStyle(LEFT), 10),
\r
291 t = parseInt(me.getStyle(TOP), 10);
\r
293 l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
\r
294 t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
\r
296 return {left: (x - o[0] + l), top: (y - o[1] + t)};
\r
299 animTest : function(args, animate, i) {
\r
300 return !!animate && this.preanim ? this.preanim(args, i) : false;
\r