3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
12 var D = Ext.lib.Dom,
\r
17 POSITION = "position",
\r
19 RELATIVE = "relative",
\r
23 function animTest(args, animate, i) {
\r
24 return this.preanim && !!animate ? this.preanim(args, i) : false
\r
27 Ext.Element.addMethods({
\r
28 <div id="method-Ext.Element-getX"></div>/**
\r
29 * 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
30 * @return {Number} The X position of the element
\r
33 return D.getX(this.dom);
\r
36 <div id="method-Ext.Element-getY"></div>/**
\r
37 * 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
38 * @return {Number} The Y position of the element
\r
41 return D.getY(this.dom);
\r
44 <div id="method-Ext.Element-getXY"></div>/**
\r
45 * 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
46 * @return {Array} The XY position of the element
\r
49 return D.getXY(this.dom);
\r
52 <div id="method-Ext.Element-getOffsetsTo"></div>/**
\r
53 * 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
54 * @param {Mixed} element The element to get the offsets from.
\r
55 * @return {Array} The XY page offsets (e.g. [100, -200])
\r
57 getOffsetsTo : function(el){
\r
58 var o = this.getXY(),
\r
59 e = Ext.fly(el, '_internal').getXY();
\r
60 return [o[0]-e[0],o[1]-e[1]];
\r
63 <div id="method-Ext.Element-setX"></div>/**
\r
64 * 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
65 * @param {Number} The X position of the element
\r
66 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
67 * @return {Ext.Element} this
\r
69 setX : function(x, animate){
\r
70 return this.setXY([x, this.getY()], animTest.call(this, arguments, animate, 1));
\r
73 <div id="method-Ext.Element-setY"></div>/**
\r
74 * 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
75 * @param {Number} The Y position of the element
\r
76 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
77 * @return {Ext.Element} this
\r
79 setY : function(y, animate){
\r
80 return this.setXY([this.getX(), y], animTest.call(this, arguments, animate, 1));
\r
83 <div id="method-Ext.Element-setLeft"></div>/**
\r
84 * Sets the element's left position directly using CSS style (instead of {@link #setX}).
\r
85 * @param {String} left The left CSS property value
\r
86 * @return {Ext.Element} this
\r
88 setLeft : function(left){
\r
89 this.setStyle(LEFT, this.addUnits(left));
\r
93 <div id="method-Ext.Element-setTop"></div>/**
\r
94 * Sets the element's top position directly using CSS style (instead of {@link #setY}).
\r
95 * @param {String} top The top CSS property value
\r
96 * @return {Ext.Element} this
\r
98 setTop : function(top){
\r
99 this.setStyle(TOP, this.addUnits(top));
\r
103 <div id="method-Ext.Element-setRight"></div>/**
\r
104 * Sets the element's CSS right style.
\r
105 * @param {String} right The right CSS property value
\r
106 * @return {Ext.Element} this
\r
108 setRight : function(right){
\r
109 this.setStyle(RIGHT, this.addUnits(right));
\r
113 <div id="method-Ext.Element-setBottom"></div>/**
\r
114 * Sets the element's CSS bottom style.
\r
115 * @param {String} bottom The bottom CSS property value
\r
116 * @return {Ext.Element} this
\r
118 setBottom : function(bottom){
\r
119 this.setStyle(BOTTOM, this.addUnits(bottom));
\r
123 <div id="method-Ext.Element-setXY"></div>/**
\r
124 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
125 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
126 * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
\r
127 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
128 * @return {Ext.Element} this
\r
130 setXY : function(pos, animate){
\r
132 if(!animate || !me.anim){
\r
133 D.setXY(me.dom, pos);
\r
135 me.anim({points: {to: pos}}, me.preanim(arguments, 1), 'motion');
\r
140 <div id="method-Ext.Element-setLocation"></div>/**
\r
141 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
142 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
143 * @param {Number} x X value for new position (coordinates are page-based)
\r
144 * @param {Number} y Y value for new position (coordinates are page-based)
\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 setLocation : function(x, y, animate){
\r
149 return this.setXY([x, y], animTest.call(this, arguments, animate, 2));
\r
152 <div id="method-Ext.Element-moveTo"></div>/**
\r
153 * Sets the position of the element in page coordinates, regardless of how the element is positioned.
\r
154 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
\r
155 * @param {Number} x X value for new position (coordinates are page-based)
\r
156 * @param {Number} y Y value for new position (coordinates are page-based)
\r
157 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
\r
158 * @return {Ext.Element} this
\r
160 moveTo : function(x, y, animate){
\r
161 return this.setXY([x, y], animTest.call(this, arguments, animate, 2));
\r
164 <div id="method-Ext.Element-getLeft"></div>/**
\r
165 * Gets the left X coordinate
\r
166 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
169 getLeft : function(local){
\r
170 return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
\r
173 <div id="method-Ext.Element-getRight"></div>/**
\r
174 * Gets the right X coordinate of the element (element X position + element width)
\r
175 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
178 getRight : function(local){
\r
180 return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
\r
183 <div id="method-Ext.Element-getTop"></div>/**
\r
184 * Gets the top Y coordinate
\r
185 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
188 getTop : function(local) {
\r
189 return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
\r
192 <div id="method-Ext.Element-getBottom"></div>/**
\r
193 * Gets the bottom Y coordinate of the element (element Y position + element height)
\r
194 * @param {Boolean} local True to get the local css position instead of page coordinate
\r
197 getBottom : function(local){
\r
199 return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
\r
202 <div id="method-Ext.Element-position"></div>/**
\r
203 * Initializes positioning on this element. If a desired position is not passed, it will make the
\r
204 * the element positioned relative IF it is not already positioned.
\r
205 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
\r
206 * @param {Number} zIndex (optional) The zIndex to apply
\r
207 * @param {Number} x (optional) Set the page X position
\r
208 * @param {Number} y (optional) Set the page Y position
\r
210 position : function(pos, zIndex, x, y){
\r
213 if(!pos && me.isStyle(POSITION, STATIC)){
\r
214 me.setStyle(POSITION, RELATIVE);
\r
216 me.setStyle(POSITION, pos);
\r
219 me.setStyle(ZINDEX, zIndex);
\r
221 if(x || y) me.setXY([x || false, y || false]);
\r
224 <div id="method-Ext.Element-clearPositioning"></div>/**
\r
225 * Clear positioning back to the default when the document was loaded
\r
226 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
\r
227 * @return {Ext.Element} this
\r
229 clearPositioning : function(value){
\r
230 value = value || '';
\r
242 <div id="method-Ext.Element-getPositioning"></div>/**
\r
243 * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
\r
244 * snapshot before performing an update and then restoring the element.
\r
247 getPositioning : function(){
\r
248 var l = this.getStyle(LEFT);
\r
249 var t = this.getStyle(TOP);
\r
251 "position" : this.getStyle(POSITION),
\r
253 "right" : l ? "" : this.getStyle(RIGHT),
\r
255 "bottom" : t ? "" : this.getStyle(BOTTOM),
\r
256 "z-index" : this.getStyle(ZINDEX)
\r
260 <div id="method-Ext.Element-setPositioning"></div>/**
\r
261 * Set positioning with an object returned by getPositioning().
\r
262 * @param {Object} posCfg
\r
263 * @return {Ext.Element} this
\r
265 setPositioning : function(pc){
\r
267 style = me.dom.style;
\r
271 if(pc.right == AUTO){
\r
274 if(pc.bottom == AUTO){
\r
281 <div id="method-Ext.Element-translatePoints"></div>/**
\r
282 * Translates the passed page coordinates into left/top css values for this element
\r
283 * @param {Number/Array} x The page x or an array containing [x, y]
\r
284 * @param {Number} y (optional) The page y, required if x is not an array
\r
285 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
\r
287 translatePoints : function(x, y){
\r
288 y = isNaN(x[1]) ? y : x[1];
\r
289 x = isNaN(x[0]) ? x : x[0];
\r
291 relative = me.isStyle(POSITION, RELATIVE),
\r
293 l = parseInt(me.getStyle(LEFT), 10),
\r
294 t = parseInt(me.getStyle(TOP), 10);
\r
296 l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
\r
297 t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
\r
299 return {left: (x - o[0] + l), top: (y - o[1] + t)};
\r
302 animTest : animTest
\r