3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
18 Ext.Element.addMethods({
19 <div id="method-Ext.Element-getAnchorXY"></div>/**
20 * Gets the x,y coordinates specified by the anchor position on the element.
21 * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo}
22 * for details on supported anchor positions.
23 * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead
25 * @param {Object} size (optional) An object containing the size to use for calculating anchor position
26 * {width: (target width), height: (target height)} (defaults to the element's current size)
27 * @return {Array} [x, y] An array containing the element's x and y coordinates
29 getAnchorXY : function(anchor, local, s){
30 //Passing a different size is useful for pre-calculating anchors,
31 //especially for anchored animations that change the el size.
32 anchor = (anchor || "tl").toLowerCase();
36 vp = me.dom == document.body || me.dom == document,
37 w = s.width || vp ? Ext.lib.Dom.getViewWidth() : me.getWidth(),
38 h = s.height || vp ? Ext.lib.Dom.getViewHeight() : me.getHeight(),
42 scroll = me.getScroll(),
43 extraX = vp ? scroll.left : !local ? o[0] : 0,
44 extraY = vp ? scroll.top : !local ? o[1] : 0,
46 c : [r(w * 0.5), r(h * 0.5)],
58 return [xy[0] + extraX, xy[1] + extraY];
61 <div id="method-Ext.Element-anchorTo"></div>/**
62 * Anchors an element to another element and realigns it when the window is resized.
63 * @param {Mixed} element The element to align to.
64 * @param {String} position The position to align to.
65 * @param {Array} offsets (optional) Offset the positioning by [x, y]
66 * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
67 * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
68 * is a number, it is used as the buffer delay (defaults to 50ms).
69 * @param {Function} callback The function to call after the animation finishes
70 * @return {Ext.Element} this
72 anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
75 scroll = !Ext.isEmpty(monitorScroll),
77 Ext.fly(dom).alignTo(el, alignment, offsets, animate);
78 Ext.callback(callback, Ext.fly(dom));
80 anchor = this.getAnchor();
82 // previous listener anchor, remove it
89 Ext.EventManager.onWindowResize(action, null);
92 Ext.EventManager.on(window, 'scroll', action, null,
93 {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
95 action.call(me); // align immediately
99 <div id="method-Ext.Element-removeAnchor"></div>/**
100 * Remove any anchor to this element. See {@link #anchorTo}.
101 * @return {Ext.Element} this
103 removeAnchor : function(){
105 anchor = this.getAnchor();
107 if(anchor && anchor.fn){
108 Ext.EventManager.removeResizeListener(anchor.fn);
110 Ext.EventManager.un(window, 'scroll', anchor.fn);
118 getAnchor : function(){
119 var data = Ext.Element.data,
124 var anchor = data(dom, '_anchor');
127 anchor = data(dom, '_anchor', {});
132 <div id="method-Ext.Element-getAlignToXY"></div>/**
133 * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
134 * supported position values.
135 * @param {Mixed} element The element to align to.
136 * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
137 * @param {Array} offsets (optional) Offset the positioning by [x, y]
138 * @return {Array} [x, y]
140 getAlignToXY : function(el, p, o){
144 throw "Element.alignToXY with an element that doesn't exist";
148 p = (!p || p == "?" ? "tl-bl?" : (!/-/.test(p) && p !== "" ? "tl-" + p : p || "tl-bl")).toLowerCase();
156 //constrain the aligned el to viewport if necessary
160 dw = Ext.lib.Dom.getViewWidth() -10, // 10px of margin for ie
161 dh = Ext.lib.Dom.getViewHeight()-10, // 10px of margin for ie
169 docElement = doc.documentElement,
171 scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0)+5,
172 scrollY = (docElement.scrollTop || docBody.scrollTop || 0)+5,
173 c = false, //constrain to viewport
176 m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
179 throw "Element.alignTo with an invalid alignment " + p;
186 //Subtract the aligned el's internal xy from the target's offset xy
187 //plus custom offset to get the aligned el's new offset xy
188 a1 = me.getAnchorXY(p1, true);
189 a2 = el.getAnchorXY(p2, false);
191 x = a2[0] - a1[0] + o[0];
192 y = a2[1] - a1[1] + o[1];
198 //If we are at a viewport boundary and the aligned el is anchored on a target border that is
199 //perpendicular to the vp border, allow the aligned el to slide on that border,
200 //otherwise swap the aligned el to the opposite border of the target.
202 p1x = p1.charAt(p1.length-1);
204 p2x = p2.charAt(p2.length-1);
205 swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
206 swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
209 if (x + w > dw + scrollX) {
210 x = swapX ? r.left-w : dw+scrollX-w;
213 x = swapX ? r.right : scrollX;
215 if (y + h > dh + scrollY) {
216 y = swapY ? r.top-h : dh+scrollY-h;
219 y = swapY ? r.bottom : scrollY;
225 <div id="method-Ext.Element-alignTo"></div>/**
226 * Aligns this element with another element relative to the specified anchor points. If the other element is the
227 * document it aligns it to the viewport.
228 * The position parameter is optional, and can be specified in any one of the following formats:
230 * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
231 * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
232 * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
233 * deprecated in favor of the newer two anchor syntax below</i>.</li>
234 * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
235 * element's anchor point, and the second value is used as the target's anchor point.</li>
237 * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
238 * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
239 * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
240 * that specified in order to enforce the viewport constraints.
241 * Following are all of the supported anchor positions:
244 ----- -----------------------------
245 tl The top left corner (default)
246 t The center of the top edge
247 tr The top right corner
248 l The center of the left edge
249 c In the center of the element
250 r The center of the right edge
251 bl The bottom left corner
252 b The center of the bottom edge
253 br The bottom right corner
257 // align el to other-el using the default positioning ("tl-bl", non-constrained)
258 el.alignTo("other-el");
260 // align the top left corner of el with the top right corner of other-el (constrained to viewport)
261 el.alignTo("other-el", "tr?");
263 // align the bottom right corner of el with the center left edge of other-el
264 el.alignTo("other-el", "br-l?");
266 // align the center of el with the bottom left corner of other-el and
267 // adjust the x position by -6 pixels (and the y position by 0)
268 el.alignTo("other-el", "c-bl", [-6, 0]);
270 * @param {Mixed} element The element to align to.
271 * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
272 * @param {Array} offsets (optional) Offset the positioning by [x, y]
273 * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
274 * @return {Ext.Element} this
276 alignTo : function(element, position, offsets, animate){
278 return me.setXY(me.getAlignToXY(element, position, offsets),
279 me.preanim && !!animate ? me.preanim(arguments, 3) : false);
282 // private ==> used outside of core
283 adjustForConstraints : function(xy, parent, offsets){
284 return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
287 // private ==> used outside of core
288 getConstrainToXY : function(el, local, offsets, proposedXY){
289 var os = {top:0, left:0, bottom:0, right: 0};
291 return function(el, local, offsets, proposedXY){
293 offsets = offsets ? Ext.applyIf(offsets, os) : os;
295 var vw, vh, vx = 0, vy = 0;
296 if(el.dom == document.body || el.dom == document){
297 vw =Ext.lib.Dom.getViewWidth();
298 vh = Ext.lib.Dom.getViewHeight();
300 vw = el.dom.clientWidth;
301 vh = el.dom.clientHeight;
303 var vxy = el.getXY();
309 var s = el.getScroll();
311 vx += offsets.left + s.left;
312 vy += offsets.top + s.top;
315 vh -= offsets.bottom;
320 var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);
321 var x = xy[0], y = xy[1];
322 var w = this.dom.offsetWidth, h = this.dom.offsetHeight;
324 // only move it if it needs it
327 // first validate right/bottom
336 // then make sure top/left isn't negative
345 return moved ? [x, y] : false;
352 // offsets = Ext.applyIf(offsets || {}, {top : 0, left : 0, bottom : 0, right : 0});
356 // s = el.getScroll(),
358 // vx = offsets.left + s.left,
359 // vy = offsets.top + s.top,
360 // vw = -offsets.right,
361 // vh = -offsets.bottom,
364 // xy = proposedXY || (!local ? me.getXY() : [me.getLeft(true), me.getTop(true)]),
367 // w = me.dom.offsetWidth, h = me.dom.offsetHeight,
368 // moved = false; // only move it if it needs it
371 // if(el.dom == doc.body || el.dom == doc){
372 // vw += Ext.lib.Dom.getViewWidth();
373 // vh += Ext.lib.Dom.getViewHeight();
375 // vw += el.dom.clientWidth;
376 // vh += el.dom.clientHeight;
383 // // first validate right/bottom
384 // if(x + w > vx + vw){
388 // if(y + h > vy + vh){
392 // // then make sure top/left isn't negative
401 // return moved ? [x, y] : false;
404 <div id="method-Ext.Element-getCenterXY"></div>/**
405 * Calculates the x, y to center this element on the screen
406 * @return {Array} The x, y values [x, y]
408 getCenterXY : function(){
409 return this.getAlignToXY(document, 'c-c');
412 <div id="method-Ext.Element-center"></div>/**
413 * Centers the Element in either the viewport, or another Element.
414 * @param {Mixed} centerIn (optional) The element in which to center the element.
416 center : function(centerIn){
417 return this.alignTo(centerIn || document, 'c-c');