4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
19 </span> * @class Ext.Element
23 var ELEMENT = Ext.Element,
24 LEFT = "left",
25 RIGHT = "right",
26 TOP = "top",
27 BOTTOM = "bottom",
28 POSITION = "position",
29 STATIC = "static",
30 RELATIVE = "relative",
31 AUTO = "auto",
32 ZINDEX = "z-index";
34 Ext.override(Ext.Element, {
35 <span id='Ext-Element-method-getX'> /**
36 </span> * 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).
37 * @return {Number} The X position of the element
40 return ELEMENT.getX(this.dom);
43 <span id='Ext-Element-method-getY'> /**
44 </span> * 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).
45 * @return {Number} The Y position of the element
48 return ELEMENT.getY(this.dom);
51 <span id='Ext-Element-method-getXY'> /**
52 </span> * 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).
53 * @return {Number[]} The XY position of the element
56 return ELEMENT.getXY(this.dom);
59 <span id='Ext-Element-method-getOffsetsTo'> /**
60 </span> * 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.
61 * @param {String/HTMLElement/Ext.Element} element The element to get the offsets from.
62 * @return {Number[]} The XY page offsets (e.g. [100, -200])
64 getOffsetsTo : function(el){
66 e = Ext.fly(el, '_internal').getXY();
67 return [o[0]-e[0],o[1]-e[1]];
70 <span id='Ext-Element-method-setX'> /**
71 </span> * 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).
72 * @param {Number} The X position of the element
73 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
74 * @return {Ext.Element} this
76 setX : function(x, animate){
77 return this.setXY([x, this.getY()], animate);
80 <span id='Ext-Element-method-setY'> /**
81 </span> * 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).
82 * @param {Number} The Y position of the element
83 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
84 * @return {Ext.Element} this
86 setY : function(y, animate){
87 return this.setXY([this.getX(), y], animate);
90 <span id='Ext-Element-method-setLeft'> /**
91 </span> * Sets the element's left position directly using CSS style (instead of {@link #setX}).
92 * @param {String} left The left CSS property value
93 * @return {Ext.Element} this
95 setLeft : function(left){
96 this.setStyle(LEFT, this.addUnits(left));
100 <span id='Ext-Element-method-setTop'> /**
101 </span> * Sets the element's top position directly using CSS style (instead of {@link #setY}).
102 * @param {String} top The top CSS property value
103 * @return {Ext.Element} this
105 setTop : function(top){
106 this.setStyle(TOP, this.addUnits(top));
110 <span id='Ext-Element-method-setRight'> /**
111 </span> * Sets the element's CSS right style.
112 * @param {String} right The right CSS property value
113 * @return {Ext.Element} this
115 setRight : function(right){
116 this.setStyle(RIGHT, this.addUnits(right));
120 <span id='Ext-Element-method-setBottom'> /**
121 </span> * Sets the element's CSS bottom style.
122 * @param {String} bottom The bottom CSS property value
123 * @return {Ext.Element} this
125 setBottom : function(bottom){
126 this.setStyle(BOTTOM, this.addUnits(bottom));
130 <span id='Ext-Element-method-setXY'> /**
131 </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
132 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
133 * @param {Number[]} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
134 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
135 * @return {Ext.Element} this
137 setXY: function(pos, animate) {
139 if (!animate || !me.anim) {
140 ELEMENT.setXY(me.dom, pos);
143 if (!Ext.isObject(animate)) {
146 me.animate(Ext.applyIf({ to: { x: pos[0], y: pos[1] } }, animate));
151 <span id='Ext-Element-method-setLocation'> /**
152 </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
153 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
154 * @param {Number} x X value for new position (coordinates are page-based)
155 * @param {Number} y Y value for new position (coordinates are page-based)
156 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
157 * @return {Ext.Element} this
159 setLocation : function(x, y, animate){
160 return this.setXY([x, y], animate);
163 <span id='Ext-Element-method-moveTo'> /**
164 </span> * Sets the position of the element in page coordinates, regardless of how the element is positioned.
165 * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
166 * @param {Number} x X value for new position (coordinates are page-based)
167 * @param {Number} y Y value for new position (coordinates are page-based)
168 * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
169 * @return {Ext.Element} this
171 moveTo : function(x, y, animate){
172 return this.setXY([x, y], animate);
175 <span id='Ext-Element-method-getLeft'> /**
176 </span> * Gets the left X coordinate
177 * @param {Boolean} local True to get the local css position instead of page coordinate
180 getLeft : function(local){
181 return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
184 <span id='Ext-Element-method-getRight'> /**
185 </span> * Gets the right X coordinate of the element (element X position + element width)
186 * @param {Boolean} local True to get the local css position instead of page coordinate
189 getRight : function(local){
191 return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
194 <span id='Ext-Element-method-getTop'> /**
195 </span> * Gets the top Y coordinate
196 * @param {Boolean} local True to get the local css position instead of page coordinate
199 getTop : function(local) {
200 return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
203 <span id='Ext-Element-method-getBottom'> /**
204 </span> * Gets the bottom Y coordinate of the element (element Y position + element height)
205 * @param {Boolean} local True to get the local css position instead of page coordinate
208 getBottom : function(local){
210 return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
213 <span id='Ext-Element-method-position'> /**
214 </span> * Initializes positioning on this element. If a desired position is not passed, it will make the
215 * the element positioned relative IF it is not already positioned.
216 * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
217 * @param {Number} zIndex (optional) The zIndex to apply
218 * @param {Number} x (optional) Set the page X position
219 * @param {Number} y (optional) Set the page Y position
221 position : function(pos, zIndex, x, y) {
224 if (!pos && me.isStyle(POSITION, STATIC)){
225 me.setStyle(POSITION, RELATIVE);
227 me.setStyle(POSITION, pos);
230 me.setStyle(ZINDEX, zIndex);
233 me.setXY([x || false, y || false]);
237 <span id='Ext-Element-method-clearPositioning'> /**
238 </span> * Clear positioning back to the default when the document was loaded
239 * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
240 * @return {Ext.Element} this
242 clearPositioning : function(value){
249 "z-index" : "",
255 <span id='Ext-Element-method-getPositioning'> /**
256 </span> * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
257 * snapshot before performing an update and then restoring the element.
260 getPositioning : function(){
261 var l = this.getStyle(LEFT);
262 var t = this.getStyle(TOP);
264 "position" : this.getStyle(POSITION),
265 "left" : l,
266 "right" : l ? "" : this.getStyle(RIGHT),
268 "bottom" : t ? "" : this.getStyle(BOTTOM),
269 "z-index" : this.getStyle(ZINDEX)
273 <span id='Ext-Element-method-setPositioning'> /**
274 </span> * Set positioning with an object returned by getPositioning().
275 * @param {Object} posCfg
276 * @return {Ext.Element} this
278 setPositioning : function(pc){
280 style = me.dom.style;
284 if(pc.right == AUTO){
285 style.right = "";
287 if(pc.bottom == AUTO){
288 style.bottom = "";
294 <span id='Ext-Element-method-translatePoints'> /**
295 </span> * Translates the passed page coordinates into left/top css values for this element
296 * @param {Number/Number[]} x The page x or an array containing [x, y]
297 * @param {Number} y (optional) The page y, required if x is not an array
298 * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
300 translatePoints: function(x, y) {
301 if (Ext.isArray(x)) {
306 relative = me.isStyle(POSITION, RELATIVE),
308 left = parseInt(me.getStyle(LEFT), 10),
309 top = parseInt(me.getStyle(TOP), 10);
311 if (!Ext.isNumber(left)) {
312 left = relative ? 0 : me.dom.offsetLeft;
314 if (!Ext.isNumber(top)) {
315 top = relative ? 0 : me.dom.offsetTop;
317 left = (Ext.isNumber(x)) ? x - o[0] + left : undefined;
318 top = (Ext.isNumber(y)) ? y - o[1] + top : undefined;
325 <span id='Ext-Element-method-setBox'> /**
326 </span> * 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.
327 * @param {Object} box The box to fill {x, y, width, height}
328 * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
329 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
330 * @return {Ext.Element} this
332 setBox: function(box, adjust, animate) {
336 if ((adjust && !me.autoBoxAdjust) && !me.isBorderBox()) {
337 w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
338 h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
340 me.setBounds(box.x, box.y, w, h, animate);
344 <span id='Ext-Element-method-getBox'> /**
345 </span> * Return an object defining the area of this Element which can be passed to {@link #setBox} to
346 * set another Element's size/location to match this element.
347 * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
348 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
349 * @return {Object} box An object in the format<pre><code>
351 x: &lt;Element's X position>,
352 y: &lt;Element's Y position>,
353 width: &lt;Element's width>,
354 height: &lt;Element's height>,
355 bottom: &lt;Element's lower bound>,
356 right: &lt;Element's rightmost bound>
358 </code></pre>
359 * The returned object may also be addressed as an Array where index 0 contains the X position
360 * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
362 getBox: function(contentBox, local) {
367 getBorderWidth = me.getBorderWidth,
368 getPadding = me.getPadding,
369 l, r, t, b, w, h, bx;
373 left = parseInt(me.getStyle("left"), 10) || 0;
374 top = parseInt(me.getStyle("top"), 10) || 0;
389 l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");
390 r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");
391 t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");
392 b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");
402 bx.right = bx.x + bx.width;
403 bx.bottom = bx.y + bx.height;
407 <span id='Ext-Element-method-move'> /**
408 </span> * Move this element relative to its current position.
409 * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
410 * @param {Number} distance How far to move the element in pixels
411 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
413 move: function(direction, distance, animate) {
418 left = [x - distance, y],
419 right = [x + distance, y],
420 top = [x, y - distance],
421 bottom = [x, y + distance],
435 direction = direction.toLowerCase();
436 me.moveTo(hash[direction][0], hash[direction][1], animate);
439 <span id='Ext-Element-method-setLeftTop'> /**
440 </span> * Quick set left and top adding default units
441 * @param {String} left The left CSS property value
442 * @param {String} top The top CSS property value
443 * @return {Ext.Element} this
445 setLeftTop: function(left, top) {
447 style = me.dom.style;
448 style.left = me.addUnits(left);
449 style.top = me.addUnits(top);
453 <span id='Ext-Element-method-getRegion'> /**
454 </span> * Returns the region of this element.
455 * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
456 * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
458 getRegion: function() {
459 return this.getPageBox(true);
462 <span id='Ext-Element-method-getViewRegion'> /**
463 </span> * Returns the <b>content</b> region of this element. That is the region within the borders and padding.
464 * @return {Ext.util.Region} A Region containing "top, left, bottom, right" member data.
466 getViewRegion: function() {
468 isBody = me.dom === document.body,
469 scroll, pos, top, left, width, height;
471 // For the body we want to do some special logic
473 scroll = me.getScroll();
476 width = Ext.Element.getViewportWidth();
477 height = Ext.Element.getViewportHeight();
481 left = pos[0] + me.getBorderWidth('l') + me.getPadding('l');
482 top = pos[1] + me.getBorderWidth('t') + me.getPadding('t');
483 width = me.getWidth(true);
484 height = me.getHeight(true);
487 return Ext.create('Ext.util.Region', top, left + width, top + height, left);
490 <span id='Ext-Element-method-getPageBox'> /**
491 </span> * Return an object defining the area of this Element which can be passed to {@link #setBox} to
492 * set another Element's size/location to match this element.
493 * @param {Boolean} asRegion(optional) If true an Ext.util.Region will be returned
494 * @return {Object} box An object in the format<pre><code>
496 x: &lt;Element's X position>,
497 y: &lt;Element's Y position>,
498 width: &lt;Element's width>,
499 height: &lt;Element's height>,
500 bottom: &lt;Element's lower bound>,
501 right: &lt;Element's rightmost bound>
503 </code></pre>
504 * The returned object may also be addressed as an Array where index 0 contains the X position
505 * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
507 getPageBox : function(getRegion) {
510 isDoc = el === document.body,
511 w = isDoc ? Ext.Element.getViewWidth() : el.offsetWidth,
512 h = isDoc ? Ext.Element.getViewHeight() : el.offsetHeight,
520 return Ext.create('Ext.util.Region', t, r, b, l);
534 <span id='Ext-Element-method-setBounds'> /**
535 </span> * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
536 * @param {Number} x X value for new position (coordinates are page-based)
537 * @param {Number} y Y value for new position (coordinates are page-based)
538 * @param {Number/String} width The new width. This may be one of:<div class="mdetail-params"><ul>
539 * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>
540 * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
541 * </ul></div>
542 * @param {Number/String} height The new height. This may be one of:<div class="mdetail-params"><ul>
543 * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>
544 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
545 * </ul></div>
546 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
547 * @return {Ext.Element} this
549 setBounds: function(x, y, width, height, animate) {
551 if (!animate || !me.anim) {
552 me.setSize(width, height);
553 me.setLocation(x, y);
555 if (!Ext.isObject(animate)) {
558 me.animate(Ext.applyIf({
562 width: me.adjustWidth(width),
563 height: me.adjustHeight(height)
570 <span id='Ext-Element-method-setRegion'> /**
571 </span> * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.
572 * @param {Ext.util.Region} region The region to fill
573 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
574 * @return {Ext.Element} this
576 setRegion: function(region, animate) {
577 return this.setBounds(region.left, region.top, region.right - region.left, region.bottom - region.top, animate);