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"><div id="cls-Ext.BoxComponent"></div>/**
10 * @class Ext.BoxComponent
11 * @extends Ext.Component
12 * <p>Base class for any {@link Ext.Component Component} that is to be sized as a box, using width and height.</p>
13 * <p>BoxComponent provides automatic box model adjustments for sizing and positioning and will work correctly
14 * within the Component rendering model.</p>
15 * <p>A BoxComponent may be created as a custom Component which encapsulates any HTML element, either a pre-existing
16 * element, or one that is created to your specifications at render time. Usually, to participate in layouts,
17 * a Component will need to be a <b>Box</b>Component in order to have its width and height managed.</p>
18 * <p>To use a pre-existing element as a BoxComponent, configure it so that you preset the <b>el</b> property to the
19 * element to reference:<pre><code>
20 var pageHeader = new Ext.BoxComponent({
23 * This may then be {@link Ext.Container#add added} to a {@link Ext.Container Container} as a child item.</p>
24 * <p>To create a BoxComponent based around a HTML element to be created at render time, use the
25 * {@link Ext.Component#autoEl autoEl} config option which takes the form of a
26 * {@link Ext.DomHelper DomHelper} specification:<pre><code>
27 var myImage = new Ext.BoxComponent({
30 src: '/images/my-image.jpg'
34 * @param {Ext.Element/String/Object} config The configuration options.
37 Ext.BoxComponent = Ext.extend(Ext.Component, {
39 // Configs below are used for all Components when rendered by BoxLayout.
40 <div id="cfg-Ext.BoxComponent-flex"></div>/**
42 * <p><b>Note</b>: this config is only used when this Component is rendered
43 * by a Container which has been configured to use a <b>{@link Ext.layout.BoxLayout BoxLayout}.</b>
44 * Each child Component with a <code>flex</code> property will be flexed either vertically (by a VBoxLayout)
45 * or horizontally (by an HBoxLayout) according to the item's <b>relative</b> <code>flex</code> value
46 * compared to the sum of all Components with <code>flex</flex> value specified. Any child items that have
47 * either a <code>flex = 0</code> or <code>flex = undefined</code> will not be 'flexed' (the initial size will not be changed).
49 // Configs below are used for all Components when rendered by AnchorLayout.
50 <div id="cfg-Ext.BoxComponent-anchor"></div>/**
51 * @cfg {String} anchor <p><b>Note</b>: this config is only used when this Component is rendered
52 * by a Container which has been configured to use an <b>{@link Ext.layout.AnchorLayout AnchorLayout} (or subclass thereof).</b>
53 * based layout manager, for example:<div class="mdetail-params"><ul>
54 * <li>{@link Ext.form.FormPanel}</li>
55 * <li>specifying <code>layout: 'anchor' // or 'form', or 'absolute'</code></li>
57 * <p>See {@link Ext.layout.AnchorLayout}.{@link Ext.layout.AnchorLayout#anchor anchor} also.</p>
59 // tabTip config is used when a BoxComponent is a child of a TabPanel
60 <div id="cfg-Ext.BoxComponent-tabTip"></div>/**
61 * @cfg {String} tabTip
62 * <p><b>Note</b>: this config is only used when this BoxComponent is a child item of a TabPanel.</p>
63 * A string to be used as innerHTML (html tags are accepted) to show in a tooltip when mousing over
64 * the associated tab selector element. {@link Ext.QuickTips}.init()
65 * must be called in order for the tips to render.
67 // Configs below are used for all Components when rendered by BorderLayout.
68 <div id="cfg-Ext.BoxComponent-region"></div>/**
69 * @cfg {String} region <p><b>Note</b>: this config is only used when this BoxComponent is rendered
70 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
71 * layout manager (e.g. specifying <tt>layout:'border'</tt>).</p><br>
72 * <p>See {@link Ext.layout.BorderLayout} also.</p>
74 // margins config is used when a BoxComponent is rendered by BorderLayout or BoxLayout.
75 <div id="cfg-Ext.BoxComponent-margins"></div>/**
76 * @cfg {Object} margins <p><b>Note</b>: this config is only used when this BoxComponent is rendered
77 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
78 * or one of the two <b>{@link Ext.layout.BoxLayout BoxLayout} subclasses.</b></p>
79 * <p>An object containing margins to apply to this BoxComponent in the
80 * format:</p><pre><code>
83 right: (right margin),
84 bottom: (bottom margin),
87 * <p>May also be a string containing space-separated, numeric margin values. The order of the
88 * sides associated with each value matches the way CSS processes margin values:</p>
89 * <p><div class="mdetail-params"><ul>
90 * <li>If there is only one value, it applies to all sides.</li>
91 * <li>If there are two values, the top and bottom borders are set to the first value and the
92 * right and left are set to the second.</li>
93 * <li>If there are three values, the top is set to the first value, the left and right are set
94 * to the second, and the bottom is set to the third.</li>
95 * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
97 * <p>Defaults to:</p><pre><code>
98 * {top:0, right:0, bottom:0, left:0}
101 <div id="cfg-Ext.BoxComponent-x"></div>/**
103 * The local x (left) coordinate for this component if contained within a positioning container.
105 <div id="cfg-Ext.BoxComponent-y"></div>/**
107 * The local y (top) coordinate for this component if contained within a positioning container.
109 <div id="cfg-Ext.BoxComponent-pageX"></div>/**
110 * @cfg {Number} pageX
111 * The page level x coordinate for this component if contained within a positioning container.
113 <div id="cfg-Ext.BoxComponent-pageY"></div>/**
114 * @cfg {Number} pageY
115 * The page level y coordinate for this component if contained within a positioning container.
117 <div id="cfg-Ext.BoxComponent-height"></div>/**
118 * @cfg {Number} height
119 * The height of this component in pixels (defaults to auto).
120 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
122 <div id="cfg-Ext.BoxComponent-width"></div>/**
123 * @cfg {Number} width
124 * The width of this component in pixels (defaults to auto).
125 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
127 <div id="cfg-Ext.BoxComponent-boxMinHeight"></div>/**
128 * @cfg {Number} boxMinHeight
129 * <p>The minimum value in pixels which this BoxComponent will set its height to.</p>
130 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
132 <div id="cfg-Ext.BoxComponent-boxMinWidth"></div>/**
133 * @cfg {Number} boxMinWidth
134 * <p>The minimum value in pixels which this BoxComponent will set its width to.</p>
135 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
137 <div id="cfg-Ext.BoxComponent-boxMaxHeight"></div>/**
138 * @cfg {Number} boxMaxHeight
139 * <p>The maximum value in pixels which this BoxComponent will set its height to.</p>
140 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
142 <div id="cfg-Ext.BoxComponent-boxMaxWidth"></div>/**
143 * @cfg {Number} boxMaxWidth
144 * <p>The maximum value in pixels which this BoxComponent will set its width to.</p>
145 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
147 <div id="cfg-Ext.BoxComponent-autoHeight"></div>/**
148 * @cfg {Boolean} autoHeight
149 * <p>True to use height:'auto', false to use fixed height (or allow it to be managed by its parent
150 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
151 * <p><b>Note</b>: Although many components inherit this config option, not all will
152 * function as expected with a height of 'auto'. Setting autoHeight:true means that the
153 * browser will manage height based on the element's contents, and that Ext will not manage it at all.</p>
154 * <p>If the <i>browser</i> is managing the height, be aware that resizes performed by the browser in response
155 * to changes within the structure of the Component cannot be detected. Therefore changes to the height might
156 * result in elements needing to be synchronized with the new height. Example:</p><pre><code>
157 var w = new Ext.Window({
162 title: 'Collapse Me',
167 beforecollapse: function() {
170 beforeexpand: function() {
173 collapse: function() {
184 <div id="cfg-Ext.BoxComponent-autoWidth"></div>/**
185 * @cfg {Boolean} autoWidth
186 * <p>True to use width:'auto', false to use fixed width (or allow it to be managed by its parent
187 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
188 * <p><b>Note</b>: Although many components inherit this config option, not all will
189 * function as expected with a width of 'auto'. Setting autoWidth:true means that the
190 * browser will manage width based on the element's contents, and that Ext will not manage it at all.</p>
191 * <p>If the <i>browser</i> is managing the width, be aware that resizes performed by the browser in response
192 * to changes within the structure of the Component cannot be detected. Therefore changes to the width might
193 * result in elements needing to be synchronized with the new width. For example, where the target element is:</p><pre><code>
194 <div id='grid-container' style='margin-left:25%;width:50%'></div>
196 * A Panel rendered into that target element must listen for browser window resize in order to relay its
197 * child items when the browser changes its width:<pre><code>
198 var myPanel = new Ext.Panel({
199 renderTo: 'grid-container',
200 monitorResize: true, // relay on browser resize
221 <div id="cfg-Ext.BoxComponent-autoScroll"></div>/**
222 * @cfg {Boolean} autoScroll
223 * <code>true</code> to use overflow:'auto' on the components layout element and show scroll bars automatically when
224 * necessary, <code>false</code> to clip any overflowing content (defaults to <code>false</code>).
227 /* // private internal config
228 * {Boolean} deferHeight
229 * True to defer height calculations to an external component, false to allow this component to set its own
230 * height (defaults to false).
234 initComponent : function(){
235 Ext.BoxComponent.superclass.initComponent.call(this);
237 <div id="event-Ext.BoxComponent-resize"></div>/**
239 * Fires after the component is resized.
240 * @param {Ext.Component} this
241 * @param {Number} adjWidth The box-adjusted width that was set
242 * @param {Number} adjHeight The box-adjusted height that was set
243 * @param {Number} rawWidth The width that was originally specified
244 * @param {Number} rawHeight The height that was originally specified
247 <div id="event-Ext.BoxComponent-move"></div>/**
249 * Fires after the component is moved.
250 * @param {Ext.Component} this
251 * @param {Number} x The new x position
252 * @param {Number} y The new y position
258 // private, set in afterRender to signify that the component has been rendered
260 // private, used to defer height settings to subclasses
263 <div id="method-Ext.BoxComponent-setSize"></div>/**
264 * Sets the width and height of this BoxComponent. This method fires the {@link #resize} event. This method can accept
265 * either width and height as separate arguments, or you can pass a size object like <code>{width:10, height:20}</code>.
266 * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
267 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
268 * <li>A String used to set the CSS width style.</li>
269 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
270 * <li><code>undefined</code> to leave the width unchanged.</li>
272 * @param {Mixed} height The new height to set (not required if a size object is passed as the first arg).
273 * This may be one of:<div class="mdetail-params"><ul>
274 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
275 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
276 * <li><code>undefined</code> to leave the height unchanged.</li>
278 * @return {Ext.BoxComponent} this
280 setSize : function(w, h){
282 // support for standard size objects
283 if(typeof w == 'object'){
284 h = w.height, w = w.width;
286 if (Ext.isDefined(w) && Ext.isDefined(this.boxMinWidth) && (w < this.boxMinWidth)) {
287 w = this.boxMinWidth;
289 if (Ext.isDefined(h) && Ext.isDefined(this.boxMinHeight) && (h < this.boxMinHeight)) {
290 h = this.boxMinHeight;
292 if (Ext.isDefined(w) && Ext.isDefined(this.boxMaxWidth) && (w > this.boxMaxWidth)) {
293 w = this.boxMaxWidth;
295 if (Ext.isDefined(h) && Ext.isDefined(this.boxMaxHeight) && (h > this.boxMaxHeight)) {
296 h = this.boxMaxHeight;
300 this.width = w, this.height = h;
304 // prevent recalcs when not needed
305 if(this.cacheSizes !== false && this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
308 this.lastSize = {width: w, height: h};
309 var adj = this.adjustSize(w, h),
313 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
314 rz = this.getResizeEl();
315 if(!this.deferHeight && aw !== undefined && ah !== undefined){
317 }else if(!this.deferHeight && ah !== undefined){
319 }else if(aw !== undefined){
322 this.onResize(aw, ah, w, h);
323 this.fireEvent('resize', this, aw, ah, w, h);
328 <div id="method-Ext.BoxComponent-setWidth"></div>/**
329 * Sets the width of the component. This method fires the {@link #resize} event.
330 * @param {Number} width The new width to setThis may be one of:<div class="mdetail-params"><ul>
331 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
332 * <li>A String used to set the CSS width style.</li>
334 * @return {Ext.BoxComponent} this
336 setWidth : function(width){
337 return this.setSize(width);
340 <div id="method-Ext.BoxComponent-setHeight"></div>/**
341 * Sets the height of the component. This method fires the {@link #resize} event.
342 * @param {Number} height The new height to set. This may be one of:<div class="mdetail-params"><ul>
343 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
344 * <li>A String used to set the CSS height style.</li>
345 * <li><i>undefined</i> to leave the height unchanged.</li>
347 * @return {Ext.BoxComponent} this
349 setHeight : function(height){
350 return this.setSize(undefined, height);
353 <div id="method-Ext.BoxComponent-getSize"></div>/**
354 * Gets the current size of the component's underlying element.
355 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
357 getSize : function(){
358 return this.getResizeEl().getSize();
361 <div id="method-Ext.BoxComponent-getWidth"></div>/**
362 * Gets the current width of the component's underlying element.
365 getWidth : function(){
366 return this.getResizeEl().getWidth();
369 <div id="method-Ext.BoxComponent-getHeight"></div>/**
370 * Gets the current height of the component's underlying element.
373 getHeight : function(){
374 return this.getResizeEl().getHeight();
377 <div id="method-Ext.BoxComponent-getOuterSize"></div>/**
378 * Gets the current size of the component's underlying element, including space taken by its margins.
379 * @return {Object} An object containing the element's size {width: (element width + left/right margins), height: (element height + top/bottom margins)}
381 getOuterSize : function(){
382 var el = this.getResizeEl();
383 return {width: el.getWidth() + el.getMargins('lr'),
384 height: el.getHeight() + el.getMargins('tb')};
387 <div id="method-Ext.BoxComponent-getPosition"></div>/**
388 * Gets the current XY position of the component's underlying element.
389 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
390 * @return {Array} The XY position of the element (e.g., [100, 200])
392 getPosition : function(local){
393 var el = this.getPositionEl();
395 return [el.getLeft(true), el.getTop(true)];
397 return this.xy || el.getXY();
400 <div id="method-Ext.BoxComponent-getBox"></div>/**
401 * Gets the current box measurements of the component's underlying element.
402 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
403 * @return {Object} box An object in the format {x, y, width, height}
405 getBox : function(local){
406 var pos = this.getPosition(local);
407 var s = this.getSize();
413 <div id="method-Ext.BoxComponent-updateBox"></div>/**
414 * Sets the current box measurements of the component's underlying element.
415 * @param {Object} box An object in the format {x, y, width, height}
416 * @return {Ext.BoxComponent} this
418 updateBox : function(box){
419 this.setSize(box.width, box.height);
420 this.setPagePosition(box.x, box.y);
424 <div id="method-Ext.BoxComponent-getResizeEl"></div>/**
425 * <p>Returns the outermost Element of this Component which defines the Components overall size.</p>
426 * <p><i>Usually</i> this will return the same Element as <code>{@link #getEl}</code>,
427 * but in some cases, a Component may have some more wrapping Elements around its main
428 * active Element.</p>
429 * <p>An example is a ComboBox. It is encased in a <i>wrapping</i> Element which
430 * contains both the <code><input></code> Element (which is what would be returned
431 * by its <code>{@link #getEl}</code> method, <i>and</i> the trigger button Element.
432 * This Element is returned as the <code>resizeEl</code>.
433 * @return {Ext.Element} The Element which is to be resized by size managing layouts.
435 getResizeEl : function(){
436 return this.resizeEl || this.el;
439 <div id="method-Ext.BoxComponent-setAutoScroll"></div>/**
440 * Sets the overflow on the content element of the component.
441 * @param {Boolean} scroll True to allow the Component to auto scroll.
442 * @return {Ext.BoxComponent} this
444 setAutoScroll : function(scroll){
446 this.getContentTarget().setOverflow(scroll ? 'auto' : '');
448 this.autoScroll = scroll;
452 <div id="method-Ext.BoxComponent-setPosition"></div>/**
453 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
454 * This method fires the {@link #move} event.
455 * @param {Number} left The new left
456 * @param {Number} top The new top
457 * @return {Ext.BoxComponent} this
459 setPosition : function(x, y){
460 if(x && typeof x[1] == 'number'){
469 var adj = this.adjustPosition(x, y);
470 var ax = adj.x, ay = adj.y;
472 var el = this.getPositionEl();
473 if(ax !== undefined || ay !== undefined){
474 if(ax !== undefined && ay !== undefined){
475 el.setLeftTop(ax, ay);
476 }else if(ax !== undefined){
478 }else if(ay !== undefined){
481 this.onPosition(ax, ay);
482 this.fireEvent('move', this, ax, ay);
487 <div id="method-Ext.BoxComponent-setPagePosition"></div>/**
488 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
489 * This method fires the {@link #move} event.
490 * @param {Number} x The new x position
491 * @param {Number} y The new y position
492 * @return {Ext.BoxComponent} this
494 setPagePosition : function(x, y){
495 if(x && typeof x[1] == 'number'){
504 if(x === undefined || y === undefined){ // cannot translate undefined points
507 var p = this.getPositionEl().translatePoints(x, y);
508 this.setPosition(p.left, p.top);
513 afterRender : function(){
514 Ext.BoxComponent.superclass.afterRender.call(this);
516 this.resizeEl = Ext.get(this.resizeEl);
519 this.positionEl = Ext.get(this.positionEl);
521 this.boxReady = true;
522 Ext.isDefined(this.autoScroll) && this.setAutoScroll(this.autoScroll);
523 this.setSize(this.width, this.height);
524 if(this.x || this.y){
525 this.setPosition(this.x, this.y);
526 }else if(this.pageX || this.pageY){
527 this.setPagePosition(this.pageX, this.pageY);
531 <div id="method-Ext.BoxComponent-syncSize"></div>/**
532 * Force the component's size to recalculate based on the underlying element's current height and width.
533 * @return {Ext.BoxComponent} this
535 syncSize : function(){
536 delete this.lastSize;
537 this.setSize(this.autoWidth ? undefined : this.getResizeEl().getWidth(), this.autoHeight ? undefined : this.getResizeEl().getHeight());
542 * Called after the component is resized, this method is empty by default but can be implemented by any
543 * subclass that needs to perform custom logic after a resize occurs.
544 * @param {Number} adjWidth The box-adjusted width that was set
545 * @param {Number} adjHeight The box-adjusted height that was set
546 * @param {Number} rawWidth The width that was originally specified
547 * @param {Number} rawHeight The height that was originally specified
549 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
553 * Called after the component is moved, this method is empty by default but can be implemented by any
554 * subclass that needs to perform custom logic after a move occurs.
555 * @param {Number} x The new x position
556 * @param {Number} y The new y position
558 onPosition : function(x, y){
563 adjustSize : function(w, h){
570 return {width : w, height: h};
574 adjustPosition : function(x, y){
575 return {x : x, y: y};
578 Ext.reg('box', Ext.BoxComponent);
581 <div id="cls-Ext.Spacer"></div>/**
583 * @extends Ext.BoxComponent
584 * <p>Used to provide a sizable space in a layout.</p>
586 * @param {Object} config
588 Ext.Spacer = Ext.extend(Ext.BoxComponent, {
591 Ext.reg('spacer', Ext.Spacer);</pre>
\r