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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.BoxComponent"></div>/**
16 * @class Ext.BoxComponent
17 * @extends Ext.Component
18 * <p>Base class for any {@link Ext.Component Component} that is to be sized as a box, using width and height.</p>
19 * <p>BoxComponent provides automatic box model adjustments for sizing and positioning and will work correctly
20 * within the Component rendering model.</p>
21 * <p>A BoxComponent may be created as a custom Component which encapsulates any HTML element, either a pre-existing
22 * element, or one that is created to your specifications at render time. Usually, to participate in layouts,
23 * a Component will need to be a <b>Box</b>Component in order to have its width and height managed.</p>
24 * <p>To use a pre-existing element as a BoxComponent, configure it so that you preset the <b>el</b> property to the
25 * element to reference:<pre><code>
26 var pageHeader = new Ext.BoxComponent({
29 * This may then be {@link Ext.Container#add added} to a {@link Ext.Container Container} as a child item.</p>
30 * <p>To create a BoxComponent based around a HTML element to be created at render time, use the
31 * {@link Ext.Component#autoEl autoEl} config option which takes the form of a
32 * {@link Ext.DomHelper DomHelper} specification:<pre><code>
33 var myImage = new Ext.BoxComponent({
36 src: '/images/my-image.jpg'
40 * @param {Ext.Element/String/Object} config The configuration options.
43 Ext.BoxComponent = Ext.extend(Ext.Component, {
45 // Configs below are used for all Components when rendered by BoxLayout.
46 <div id="cfg-Ext.BoxComponent-flex"></div>/**
48 * <p><b>Note</b>: this config is only used when this Component is rendered
49 * by a Container which has been configured to use a <b>{@link Ext.layout.BoxLayout BoxLayout}.</b>
50 * Each child Component with a <code>flex</code> property will be flexed either vertically (by a VBoxLayout)
51 * or horizontally (by an HBoxLayout) according to the item's <b>relative</b> <code>flex</code> value
52 * compared to the sum of all Components with <code>flex</flex> value specified. Any child items that have
53 * either a <code>flex = 0</code> or <code>flex = undefined</code> will not be 'flexed' (the initial size will not be changed).
55 // Configs below are used for all Components when rendered by AnchorLayout.
56 <div id="cfg-Ext.BoxComponent-anchor"></div>/**
57 * @cfg {String} anchor <p><b>Note</b>: this config is only used when this Component is rendered
58 * by a Container which has been configured to use an <b>{@link Ext.layout.AnchorLayout AnchorLayout} (or subclass thereof).</b>
59 * based layout manager, for example:<div class="mdetail-params"><ul>
60 * <li>{@link Ext.form.FormPanel}</li>
61 * <li>specifying <code>layout: 'anchor' // or 'form', or 'absolute'</code></li>
63 * <p>See {@link Ext.layout.AnchorLayout}.{@link Ext.layout.AnchorLayout#anchor anchor} also.</p>
65 // tabTip config is used when a BoxComponent is a child of a TabPanel
66 <div id="cfg-Ext.BoxComponent-tabTip"></div>/**
67 * @cfg {String} tabTip
68 * <p><b>Note</b>: this config is only used when this BoxComponent is a child item of a TabPanel.</p>
69 * A string to be used as innerHTML (html tags are accepted) to show in a tooltip when mousing over
70 * the associated tab selector element. {@link Ext.QuickTips}.init()
71 * must be called in order for the tips to render.
73 // Configs below are used for all Components when rendered by BorderLayout.
74 <div id="cfg-Ext.BoxComponent-region"></div>/**
75 * @cfg {String} region <p><b>Note</b>: this config is only used when this BoxComponent is rendered
76 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
77 * layout manager (e.g. specifying <tt>layout:'border'</tt>).</p><br>
78 * <p>See {@link Ext.layout.BorderLayout} also.</p>
80 // margins config is used when a BoxComponent is rendered by BorderLayout or BoxLayout.
81 <div id="cfg-Ext.BoxComponent-margins"></div>/**
82 * @cfg {Object} margins <p><b>Note</b>: this config is only used when this BoxComponent is rendered
83 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
84 * or one of the two <b>{@link Ext.layout.BoxLayout BoxLayout} subclasses.</b></p>
85 * <p>An object containing margins to apply to this BoxComponent in the
86 * format:</p><pre><code>
89 right: (right margin),
90 bottom: (bottom margin),
93 * <p>May also be a string containing space-separated, numeric margin values. The order of the
94 * sides associated with each value matches the way CSS processes margin values:</p>
95 * <p><div class="mdetail-params"><ul>
96 * <li>If there is only one value, it applies to all sides.</li>
97 * <li>If there are two values, the top and bottom borders are set to the first value and the
98 * right and left are set to the second.</li>
99 * <li>If there are three values, the top is set to the first value, the left and right are set
100 * to the second, and the bottom is set to the third.</li>
101 * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
103 * <p>Defaults to:</p><pre><code>
104 * {top:0, right:0, bottom:0, left:0}
107 <div id="cfg-Ext.BoxComponent-x"></div>/**
109 * The local x (left) coordinate for this component if contained within a positioning container.
111 <div id="cfg-Ext.BoxComponent-y"></div>/**
113 * The local y (top) coordinate for this component if contained within a positioning container.
115 <div id="cfg-Ext.BoxComponent-pageX"></div>/**
116 * @cfg {Number} pageX
117 * The page level x coordinate for this component if contained within a positioning container.
119 <div id="cfg-Ext.BoxComponent-pageY"></div>/**
120 * @cfg {Number} pageY
121 * The page level y coordinate for this component if contained within a positioning container.
123 <div id="cfg-Ext.BoxComponent-height"></div>/**
124 * @cfg {Number} height
125 * The height of this component in pixels (defaults to auto).
126 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
128 <div id="cfg-Ext.BoxComponent-width"></div>/**
129 * @cfg {Number} width
130 * The width of this component in pixels (defaults to auto).
131 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
133 <div id="cfg-Ext.BoxComponent-boxMinHeight"></div>/**
134 * @cfg {Number} boxMinHeight
135 * <p>The minimum value in pixels which this BoxComponent will set its height to.</p>
136 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
138 <div id="cfg-Ext.BoxComponent-boxMinWidth"></div>/**
139 * @cfg {Number} boxMinWidth
140 * <p>The minimum value in pixels which this BoxComponent will set its width to.</p>
141 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
143 <div id="cfg-Ext.BoxComponent-boxMaxHeight"></div>/**
144 * @cfg {Number} boxMaxHeight
145 * <p>The maximum value in pixels which this BoxComponent will set its height to.</p>
146 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
148 <div id="cfg-Ext.BoxComponent-boxMaxWidth"></div>/**
149 * @cfg {Number} boxMaxWidth
150 * <p>The maximum value in pixels which this BoxComponent will set its width to.</p>
151 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
153 <div id="cfg-Ext.BoxComponent-autoHeight"></div>/**
154 * @cfg {Boolean} autoHeight
155 * <p>True to use height:'auto', false to use fixed height (or allow it to be managed by its parent
156 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
157 * <p><b>Note</b>: Although many components inherit this config option, not all will
158 * function as expected with a height of 'auto'. Setting autoHeight:true means that the
159 * browser will manage height based on the element's contents, and that Ext will not manage it at all.</p>
160 * <p>If the <i>browser</i> is managing the height, be aware that resizes performed by the browser in response
161 * to changes within the structure of the Component cannot be detected. Therefore changes to the height might
162 * result in elements needing to be synchronized with the new height. Example:</p><pre><code>
163 var w = new Ext.Window({
168 title: 'Collapse Me',
173 beforecollapse: function() {
176 beforeexpand: function() {
179 collapse: function() {
190 <div id="cfg-Ext.BoxComponent-autoWidth"></div>/**
191 * @cfg {Boolean} autoWidth
192 * <p>True to use width:'auto', false to use fixed width (or allow it to be managed by its parent
193 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
194 * <p><b>Note</b>: Although many components inherit this config option, not all will
195 * function as expected with a width of 'auto'. Setting autoWidth:true means that the
196 * browser will manage width based on the element's contents, and that Ext will not manage it at all.</p>
197 * <p>If the <i>browser</i> is managing the width, be aware that resizes performed by the browser in response
198 * to changes within the structure of the Component cannot be detected. Therefore changes to the width might
199 * result in elements needing to be synchronized with the new width. For example, where the target element is:</p><pre><code>
200 <div id='grid-container' style='margin-left:25%;width:50%'></div>
202 * A Panel rendered into that target element must listen for browser window resize in order to relay its
203 * child items when the browser changes its width:<pre><code>
204 var myPanel = new Ext.Panel({
205 renderTo: 'grid-container',
206 monitorResize: true, // relay on browser resize
227 <div id="cfg-Ext.BoxComponent-autoScroll"></div>/**
228 * @cfg {Boolean} autoScroll
229 * <code>true</code> to use overflow:'auto' on the components layout element and show scroll bars automatically when
230 * necessary, <code>false</code> to clip any overflowing content (defaults to <code>false</code>).
233 /* // private internal config
234 * {Boolean} deferHeight
235 * True to defer height calculations to an external component, false to allow this component to set its own
236 * height (defaults to false).
240 initComponent : function(){
241 Ext.BoxComponent.superclass.initComponent.call(this);
243 <div id="event-Ext.BoxComponent-resize"></div>/**
245 * Fires after the component is resized.
246 * @param {Ext.Component} this
247 * @param {Number} adjWidth The box-adjusted width that was set
248 * @param {Number} adjHeight The box-adjusted height that was set
249 * @param {Number} rawWidth The width that was originally specified
250 * @param {Number} rawHeight The height that was originally specified
253 <div id="event-Ext.BoxComponent-move"></div>/**
255 * Fires after the component is moved.
256 * @param {Ext.Component} this
257 * @param {Number} x The new x position
258 * @param {Number} y The new y position
264 // private, set in afterRender to signify that the component has been rendered
266 // private, used to defer height settings to subclasses
269 <div id="method-Ext.BoxComponent-setSize"></div>/**
270 * Sets the width and height of this BoxComponent. This method fires the {@link #resize} event. This method can accept
271 * either width and height as separate arguments, or you can pass a size object like <code>{width:10, height:20}</code>.
272 * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
273 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
274 * <li>A String used to set the CSS width style.</li>
275 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
276 * <li><code>undefined</code> to leave the width unchanged.</li>
278 * @param {Mixed} height The new height to set (not required if a size object is passed as the first arg).
279 * This may be one of:<div class="mdetail-params"><ul>
280 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
281 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
282 * <li><code>undefined</code> to leave the height unchanged.</li>
284 * @return {Ext.BoxComponent} this
286 setSize : function(w, h){
288 // support for standard size objects
289 if(typeof w == 'object'){
293 if (Ext.isDefined(w) && Ext.isDefined(this.boxMinWidth) && (w < this.boxMinWidth)) {
294 w = this.boxMinWidth;
296 if (Ext.isDefined(h) && Ext.isDefined(this.boxMinHeight) && (h < this.boxMinHeight)) {
297 h = this.boxMinHeight;
299 if (Ext.isDefined(w) && Ext.isDefined(this.boxMaxWidth) && (w > this.boxMaxWidth)) {
300 w = this.boxMaxWidth;
302 if (Ext.isDefined(h) && Ext.isDefined(this.boxMaxHeight) && (h > this.boxMaxHeight)) {
303 h = this.boxMaxHeight;
312 // prevent recalcs when not needed
313 if(this.cacheSizes !== false && this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
316 this.lastSize = {width: w, height: h};
317 var adj = this.adjustSize(w, h),
321 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
322 rz = this.getResizeEl();
323 if(!this.deferHeight && aw !== undefined && ah !== undefined){
325 }else if(!this.deferHeight && ah !== undefined){
327 }else if(aw !== undefined){
330 this.onResize(aw, ah, w, h);
331 this.fireEvent('resize', this, aw, ah, w, h);
336 <div id="method-Ext.BoxComponent-setWidth"></div>/**
337 * Sets the width of the component. This method fires the {@link #resize} event.
338 * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
339 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
340 * <li>A String used to set the CSS width style.</li>
342 * @return {Ext.BoxComponent} this
344 setWidth : function(width){
345 return this.setSize(width);
348 <div id="method-Ext.BoxComponent-setHeight"></div>/**
349 * Sets the height of the component. This method fires the {@link #resize} event.
350 * @param {Mixed} height The new height to set. This may be one of:<div class="mdetail-params"><ul>
351 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit defaultUnit}s (by default, pixels).</li>
352 * <li>A String used to set the CSS height style.</li>
353 * <li><i>undefined</i> to leave the height unchanged.</li>
355 * @return {Ext.BoxComponent} this
357 setHeight : function(height){
358 return this.setSize(undefined, height);
361 <div id="method-Ext.BoxComponent-getSize"></div>/**
362 * Gets the current size of the component's underlying element.
363 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
365 getSize : function(){
366 return this.getResizeEl().getSize();
369 <div id="method-Ext.BoxComponent-getWidth"></div>/**
370 * Gets the current width of the component's underlying element.
373 getWidth : function(){
374 return this.getResizeEl().getWidth();
377 <div id="method-Ext.BoxComponent-getHeight"></div>/**
378 * Gets the current height of the component's underlying element.
381 getHeight : function(){
382 return this.getResizeEl().getHeight();
385 <div id="method-Ext.BoxComponent-getOuterSize"></div>/**
386 * Gets the current size of the component's underlying element, including space taken by its margins.
387 * @return {Object} An object containing the element's size {width: (element width + left/right margins), height: (element height + top/bottom margins)}
389 getOuterSize : function(){
390 var el = this.getResizeEl();
391 return {width: el.getWidth() + el.getMargins('lr'),
392 height: el.getHeight() + el.getMargins('tb')};
395 <div id="method-Ext.BoxComponent-getPosition"></div>/**
396 * Gets the current XY position of the component's underlying element.
397 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
398 * @return {Array} The XY position of the element (e.g., [100, 200])
400 getPosition : function(local){
401 var el = this.getPositionEl();
403 return [el.getLeft(true), el.getTop(true)];
405 return this.xy || el.getXY();
408 <div id="method-Ext.BoxComponent-getBox"></div>/**
409 * Gets the current box measurements of the component's underlying element.
410 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
411 * @return {Object} box An object in the format {x, y, width, height}
413 getBox : function(local){
414 var pos = this.getPosition(local);
415 var s = this.getSize();
421 <div id="method-Ext.BoxComponent-updateBox"></div>/**
422 * Sets the current box measurements of the component's underlying element.
423 * @param {Object} box An object in the format {x, y, width, height}
424 * @return {Ext.BoxComponent} this
426 updateBox : function(box){
427 this.setSize(box.width, box.height);
428 this.setPagePosition(box.x, box.y);
432 <div id="method-Ext.BoxComponent-getResizeEl"></div>/**
433 * <p>Returns the outermost Element of this Component which defines the Components overall size.</p>
434 * <p><i>Usually</i> this will return the same Element as <code>{@link #getEl}</code>,
435 * but in some cases, a Component may have some more wrapping Elements around its main
436 * active Element.</p>
437 * <p>An example is a ComboBox. It is encased in a <i>wrapping</i> Element which
438 * contains both the <code><input></code> Element (which is what would be returned
439 * by its <code>{@link #getEl}</code> method, <i>and</i> the trigger button Element.
440 * This Element is returned as the <code>resizeEl</code>.
441 * @return {Ext.Element} The Element which is to be resized by size managing layouts.
443 getResizeEl : function(){
444 return this.resizeEl || this.el;
447 <div id="method-Ext.BoxComponent-setAutoScroll"></div>/**
448 * Sets the overflow on the content element of the component.
449 * @param {Boolean} scroll True to allow the Component to auto scroll.
450 * @return {Ext.BoxComponent} this
452 setAutoScroll : function(scroll){
454 this.getContentTarget().setOverflow(scroll ? 'auto' : '');
456 this.autoScroll = scroll;
460 <div id="method-Ext.BoxComponent-setPosition"></div>/**
461 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
462 * This method fires the {@link #move} event.
463 * @param {Number} left The new left
464 * @param {Number} top The new top
465 * @return {Ext.BoxComponent} this
467 setPosition : function(x, y){
468 if(x && typeof x[1] == 'number'){
477 var adj = this.adjustPosition(x, y);
478 var ax = adj.x, ay = adj.y;
480 var el = this.getPositionEl();
481 if(ax !== undefined || ay !== undefined){
482 if(ax !== undefined && ay !== undefined){
483 el.setLeftTop(ax, ay);
484 }else if(ax !== undefined){
486 }else if(ay !== undefined){
489 this.onPosition(ax, ay);
490 this.fireEvent('move', this, ax, ay);
495 <div id="method-Ext.BoxComponent-setPagePosition"></div>/**
496 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
497 * This method fires the {@link #move} event.
498 * @param {Number} x The new x position
499 * @param {Number} y The new y position
500 * @return {Ext.BoxComponent} this
502 setPagePosition : function(x, y){
503 if(x && typeof x[1] == 'number'){
512 if(x === undefined || y === undefined){ // cannot translate undefined points
515 var p = this.getPositionEl().translatePoints(x, y);
516 this.setPosition(p.left, p.top);
521 afterRender : function(){
522 Ext.BoxComponent.superclass.afterRender.call(this);
524 this.resizeEl = Ext.get(this.resizeEl);
527 this.positionEl = Ext.get(this.positionEl);
529 this.boxReady = true;
530 Ext.isDefined(this.autoScroll) && this.setAutoScroll(this.autoScroll);
531 this.setSize(this.width, this.height);
532 if(this.x || this.y){
533 this.setPosition(this.x, this.y);
534 }else if(this.pageX || this.pageY){
535 this.setPagePosition(this.pageX, this.pageY);
539 <div id="method-Ext.BoxComponent-syncSize"></div>/**
540 * Force the component's size to recalculate based on the underlying element's current height and width.
541 * @return {Ext.BoxComponent} this
543 syncSize : function(){
544 delete this.lastSize;
545 this.setSize(this.autoWidth ? undefined : this.getResizeEl().getWidth(), this.autoHeight ? undefined : this.getResizeEl().getHeight());
550 * Called after the component is resized, this method is empty by default but can be implemented by any
551 * subclass that needs to perform custom logic after a resize occurs.
552 * @param {Number} adjWidth The box-adjusted width that was set
553 * @param {Number} adjHeight The box-adjusted height that was set
554 * @param {Number} rawWidth The width that was originally specified
555 * @param {Number} rawHeight The height that was originally specified
557 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
561 * Called after the component is moved, this method is empty by default but can be implemented by any
562 * subclass that needs to perform custom logic after a move occurs.
563 * @param {Number} x The new x position
564 * @param {Number} y The new y position
566 onPosition : function(x, y){
571 adjustSize : function(w, h){
578 return {width : w, height: h};
582 adjustPosition : function(x, y){
583 return {x : x, y: y};
586 Ext.reg('box', Ext.BoxComponent);
589 <div id="cls-Ext.Spacer"></div>/**
591 * @extends Ext.BoxComponent
592 * <p>Used to provide a sizable space in a layout.</p>
594 * @param {Object} config
596 Ext.Spacer = Ext.extend(Ext.BoxComponent, {
599 Ext.reg('spacer', Ext.Spacer);</pre>