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 // tabTip config is used when a BoxComponent is a child of a TabPanel
40 <div id="cfg-Ext.BoxComponent-tabTip"></div>/**
41 * @cfg {String} tabTip
42 * <p><b>Note</b>: this config is only used when this BoxComponent is a child item of a TabPanel.</p>
43 * A string to be used as innerHTML (html tags are accepted) to show in a tooltip when mousing over
44 * the associated tab selector element. {@link Ext.QuickTips}.init()
45 * must be called in order for the tips to render.
47 // Configs below are used for all Components when rendered by BorderLayout.
48 <div id="cfg-Ext.BoxComponent-region"></div>/**
49 * @cfg {String} region <p><b>Note</b>: this config is only used when this BoxComponent is rendered
50 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
51 * layout manager (e.g. specifying <tt>layout:'border'</tt>).</p><br>
52 * <p>See {@link Ext.layout.BorderLayout} also.</p>
54 // margins config is used when a BoxComponent is rendered by BorderLayout or BoxLayout.
55 <div id="cfg-Ext.BoxComponent-margins"></div>/**
56 * @cfg {Object} margins <p><b>Note</b>: this config is only used when this BoxComponent is rendered
57 * by a Container which has been configured to use the <b>{@link Ext.layout.BorderLayout BorderLayout}</b>
58 * or one of the two <b>{@link Ext.layout.BoxLayout BoxLayout} subclasses.</b></p>
59 * <p>An object containing margins to apply to this BoxComponent in the
60 * format:</p><pre><code>
63 right: (right margin),
64 bottom: (bottom margin),
67 * <p>May also be a string containing space-separated, numeric margin values. The order of the
68 * sides associated with each value matches the way CSS processes margin values:</p>
69 * <p><div class="mdetail-params"><ul>
70 * <li>If there is only one value, it applies to all sides.</li>
71 * <li>If there are two values, the top and bottom borders are set to the first value and the
72 * right and left are set to the second.</li>
73 * <li>If there are three values, the top is set to the first value, the left and right are set
74 * to the second, and the bottom is set to the third.</li>
75 * <li>If there are four values, they apply to the top, right, bottom, and left, respectively.</li>
77 * <p>Defaults to:</p><pre><code>
78 * {top:0, right:0, bottom:0, left:0}
81 <div id="cfg-Ext.BoxComponent-x"></div>/**
83 * The local x (left) coordinate for this component if contained within a positioning container.
85 <div id="cfg-Ext.BoxComponent-y"></div>/**
87 * The local y (top) coordinate for this component if contained within a positioning container.
89 <div id="cfg-Ext.BoxComponent-pageX"></div>/**
91 * The page level x coordinate for this component if contained within a positioning container.
93 <div id="cfg-Ext.BoxComponent-pageY"></div>/**
95 * The page level y coordinate for this component if contained within a positioning container.
97 <div id="cfg-Ext.BoxComponent-height"></div>/**
98 * @cfg {Number} height
99 * The height of this component in pixels (defaults to auto).
100 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
102 <div id="cfg-Ext.BoxComponent-width"></div>/**
103 * @cfg {Number} width
104 * The width of this component in pixels (defaults to auto).
105 * <b>Note</b> to express this dimension as a percentage or offset see {@link Ext.Component#anchor}.
107 <div id="cfg-Ext.BoxComponent-boxMinHeight"></div>/**
108 * @cfg {Number} boxMinHeight
109 * <p>The minimum value in pixels which this BoxComponent will set its height to.</p>
110 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
112 <div id="cfg-Ext.BoxComponent-boxMinWidth"></div>/**
113 * @cfg {Number} boxMinWidth
114 * <p>The minimum value in pixels which this BoxComponent will set its width to.</p>
115 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
117 <div id="cfg-Ext.BoxComponent-boxMaxHeight"></div>/**
118 * @cfg {Number} boxMaxHeight
119 * <p>The maximum value in pixels which this BoxComponent will set its height to.</p>
120 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
122 <div id="cfg-Ext.BoxComponent-boxMaxWidth"></div>/**
123 * @cfg {Number} boxMaxWidth
124 * <p>The maximum value in pixels which this BoxComponent will set its width to.</p>
125 * <p><b>Warning:</b> This will override any size management applied by layout managers.</p>
127 <div id="cfg-Ext.BoxComponent-autoHeight"></div>/**
128 * @cfg {Boolean} autoHeight
129 * <p>True to use height:'auto', false to use fixed height (or allow it to be managed by its parent
130 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
131 * <p><b>Note</b>: Although many components inherit this config option, not all will
132 * function as expected with a height of 'auto'. Setting autoHeight:true means that the
133 * browser will manage height based on the element's contents, and that Ext will not manage it at all.</p>
134 * <p>If the <i>browser</i> is managing the height, be aware that resizes performed by the browser in response
135 * to changes within the structure of the Component cannot be detected. Therefore changes to the height might
136 * result in elements needing to be synchronized with the new height. Example:</p><pre><code>
137 var w = new Ext.Window({
142 title: 'Collapse Me',
147 beforecollapse: function() {
150 beforeexpand: function() {
153 collapse: function() {
164 <div id="cfg-Ext.BoxComponent-autoWidth"></div>/**
165 * @cfg {Boolean} autoWidth
166 * <p>True to use width:'auto', false to use fixed width (or allow it to be managed by its parent
167 * Container's {@link Ext.Container#layout layout manager}. Defaults to false.</p>
168 * <p><b>Note</b>: Although many components inherit this config option, not all will
169 * function as expected with a width of 'auto'. Setting autoWidth:true means that the
170 * browser will manage width based on the element's contents, and that Ext will not manage it at all.</p>
171 * <p>If the <i>browser</i> is managing the width, be aware that resizes performed by the browser in response
172 * to changes within the structure of the Component cannot be detected. Therefore changes to the width might
173 * result in elements needing to be synchronized with the new width. For example, where the target element is:</p><pre><code>
174 <div id='grid-container' style='margin-left:25%;width:50%'></div>
176 * A Panel rendered into that target element must listen for browser window resize in order to relay its
177 * child items when the browser changes its width:<pre><code>
178 var myPanel = new Ext.Panel({
179 renderTo: 'grid-container',
180 monitorResize: true, // relay on browser resize
201 <div id="cfg-Ext.BoxComponent-autoScroll"></div>/**
202 * @cfg {Boolean} autoScroll
203 * <code>true</code> to use overflow:'auto' on the components layout element and show scroll bars automatically when
204 * necessary, <code>false</code> to clip any overflowing content (defaults to <code>false</code>).
207 /* // private internal config
208 * {Boolean} deferHeight
209 * True to defer height calculations to an external component, false to allow this component to set its own
210 * height (defaults to false).
214 initComponent : function(){
215 Ext.BoxComponent.superclass.initComponent.call(this);
217 <div id="event-Ext.BoxComponent-resize"></div>/**
219 * Fires after the component is resized.
220 * @param {Ext.Component} this
221 * @param {Number} adjWidth The box-adjusted width that was set
222 * @param {Number} adjHeight The box-adjusted height that was set
223 * @param {Number} rawWidth The width that was originally specified
224 * @param {Number} rawHeight The height that was originally specified
227 <div id="event-Ext.BoxComponent-move"></div>/**
229 * Fires after the component is moved.
230 * @param {Ext.Component} this
231 * @param {Number} x The new x position
232 * @param {Number} y The new y position
238 // private, set in afterRender to signify that the component has been rendered
240 // private, used to defer height settings to subclasses
243 <div id="method-Ext.BoxComponent-setSize"></div>/**
244 * Sets the width and height of this BoxComponent. This method fires the {@link #resize} event. This method can accept
245 * either width and height as separate arguments, or you can pass a size object like <code>{width:10, height:20}</code>.
246 * @param {Mixed} width The new width to set. This may be one of:<div class="mdetail-params"><ul>
247 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
248 * <li>A String used to set the CSS width style.</li>
249 * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
250 * <li><code>undefined</code> to leave the width unchanged.</li>
252 * @param {Mixed} height The new height to set (not required if a size object is passed as the first arg).
253 * This may be one of:<div class="mdetail-params"><ul>
254 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
255 * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
256 * <li><code>undefined</code> to leave the height unchanged.</li>
258 * @return {Ext.BoxComponent} this
260 setSize : function(w, h){
262 // support for standard size objects
263 if(typeof w == 'object'){
264 h = w.height, w = w.width;
266 if (Ext.isDefined(w) && Ext.isDefined(this.boxMinWidth) && (w < this.boxMinWidth)) {
267 w = this.boxMinWidth;
269 if (Ext.isDefined(h) && Ext.isDefined(this.boxMinHeight) && (h < this.boxMinHeight)) {
270 h = this.boxMinHeight;
272 if (Ext.isDefined(w) && Ext.isDefined(this.boxMaxWidth) && (w > this.boxMaxWidth)) {
273 w = this.boxMaxWidth;
275 if (Ext.isDefined(h) && Ext.isDefined(this.boxMaxHeight) && (h > this.boxMaxHeight)) {
276 h = this.boxMaxHeight;
280 this.width = w, this.height = h;
284 // prevent recalcs when not needed
285 if(this.cacheSizes !== false && this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
288 this.lastSize = {width: w, height: h};
289 var adj = this.adjustSize(w, h),
293 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
294 rz = this.getResizeEl();
295 if(!this.deferHeight && aw !== undefined && ah !== undefined){
297 }else if(!this.deferHeight && ah !== undefined){
299 }else if(aw !== undefined){
302 this.onResize(aw, ah, w, h);
307 <div id="method-Ext.BoxComponent-setWidth"></div>/**
308 * Sets the width of the component. This method fires the {@link #resize} event.
309 * @param {Number} width The new width to setThis may be one of:<div class="mdetail-params"><ul>
310 * <li>A Number specifying the new width in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
311 * <li>A String used to set the CSS width style.</li>
313 * @return {Ext.BoxComponent} this
315 setWidth : function(width){
316 return this.setSize(width);
319 <div id="method-Ext.BoxComponent-setHeight"></div>/**
320 * Sets the height of the component. This method fires the {@link #resize} event.
321 * @param {Number} height The new height to set. This may be one of:<div class="mdetail-params"><ul>
322 * <li>A Number specifying the new height in the {@link #getEl Element}'s {@link Ext.Element#defaultUnit}s (by default, pixels).</li>
323 * <li>A String used to set the CSS height style.</li>
324 * <li><i>undefined</i> to leave the height unchanged.</li>
326 * @return {Ext.BoxComponent} this
328 setHeight : function(height){
329 return this.setSize(undefined, height);
332 <div id="method-Ext.BoxComponent-getSize"></div>/**
333 * Gets the current size of the component's underlying element.
334 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
336 getSize : function(){
337 return this.getResizeEl().getSize();
340 <div id="method-Ext.BoxComponent-getWidth"></div>/**
341 * Gets the current width of the component's underlying element.
344 getWidth : function(){
345 return this.getResizeEl().getWidth();
348 <div id="method-Ext.BoxComponent-getHeight"></div>/**
349 * Gets the current height of the component's underlying element.
352 getHeight : function(){
353 return this.getResizeEl().getHeight();
356 <div id="method-Ext.BoxComponent-getOuterSize"></div>/**
357 * Gets the current size of the component's underlying element, including space taken by its margins.
358 * @return {Object} An object containing the element's size {width: (element width + left/right margins), height: (element height + top/bottom margins)}
360 getOuterSize : function(){
361 var el = this.getResizeEl();
362 return {width: el.getWidth() + el.getMargins('lr'),
363 height: el.getHeight() + el.getMargins('tb')};
366 <div id="method-Ext.BoxComponent-getPosition"></div>/**
367 * Gets the current XY position of the component's underlying element.
368 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
369 * @return {Array} The XY position of the element (e.g., [100, 200])
371 getPosition : function(local){
372 var el = this.getPositionEl();
374 return [el.getLeft(true), el.getTop(true)];
376 return this.xy || el.getXY();
379 <div id="method-Ext.BoxComponent-getBox"></div>/**
380 * Gets the current box measurements of the component's underlying element.
381 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
382 * @return {Object} box An object in the format {x, y, width, height}
384 getBox : function(local){
385 var pos = this.getPosition(local);
386 var s = this.getSize();
392 <div id="method-Ext.BoxComponent-updateBox"></div>/**
393 * Sets the current box measurements of the component's underlying element.
394 * @param {Object} box An object in the format {x, y, width, height}
395 * @return {Ext.BoxComponent} this
397 updateBox : function(box){
398 this.setSize(box.width, box.height);
399 this.setPagePosition(box.x, box.y);
403 <div id="method-Ext.BoxComponent-getResizeEl"></div>/**
404 * <p>Returns the outermost Element of this Component which defines the Components overall size.</p>
405 * <p><i>Usually</i> this will return the same Element as <code>{@link #getEl}</code>,
406 * but in some cases, a Component may have some more wrapping Elements around its main
407 * active Element.</p>
408 * <p>An example is a ComboBox. It is encased in a <i>wrapping</i> Element which
409 * contains both the <code><input></code> Element (which is what would be returned
410 * by its <code>{@link #getEl}</code> method, <i>and</i> the trigger button Element.
411 * This Element is returned as the <code>resizeEl</code>.
412 * @return {Ext.Element} The Element which is to be resized by size managing layouts.
414 getResizeEl : function(){
415 return this.resizeEl || this.el;
418 <div id="method-Ext.BoxComponent-setAutoScroll"></div>/**
419 * Sets the overflow on the content element of the component.
420 * @param {Boolean} scroll True to allow the Component to auto scroll.
421 * @return {Ext.BoxComponent} this
423 setAutoScroll : function(scroll){
425 this.getContentTarget().setOverflow(scroll ? 'auto' : '');
427 this.autoScroll = scroll;
431 <div id="method-Ext.BoxComponent-setPosition"></div>/**
432 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
433 * This method fires the {@link #move} event.
434 * @param {Number} left The new left
435 * @param {Number} top The new top
436 * @return {Ext.BoxComponent} this
438 setPosition : function(x, y){
439 if(x && typeof x[1] == 'number'){
448 var adj = this.adjustPosition(x, y);
449 var ax = adj.x, ay = adj.y;
451 var el = this.getPositionEl();
452 if(ax !== undefined || ay !== undefined){
453 if(ax !== undefined && ay !== undefined){
454 el.setLeftTop(ax, ay);
455 }else if(ax !== undefined){
457 }else if(ay !== undefined){
460 this.onPosition(ax, ay);
461 this.fireEvent('move', this, ax, ay);
466 <div id="method-Ext.BoxComponent-setPagePosition"></div>/**
467 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
468 * This method fires the {@link #move} event.
469 * @param {Number} x The new x position
470 * @param {Number} y The new y position
471 * @return {Ext.BoxComponent} this
473 setPagePosition : function(x, y){
474 if(x && typeof x[1] == 'number'){
483 if(x === undefined || y === undefined){ // cannot translate undefined points
486 var p = this.getPositionEl().translatePoints(x, y);
487 this.setPosition(p.left, p.top);
492 afterRender : function(){
493 Ext.BoxComponent.superclass.afterRender.call(this);
495 this.resizeEl = Ext.get(this.resizeEl);
498 this.positionEl = Ext.get(this.positionEl);
500 this.boxReady = true;
501 this.setAutoScroll(this.autoScroll);
502 this.setSize(this.width, this.height);
503 if(this.x || this.y){
504 this.setPosition(this.x, this.y);
505 }else if(this.pageX || this.pageY){
506 this.setPagePosition(this.pageX, this.pageY);
510 <div id="method-Ext.BoxComponent-syncSize"></div>/**
511 * Force the component's size to recalculate based on the underlying element's current height and width.
512 * @return {Ext.BoxComponent} this
514 syncSize : function(){
515 delete this.lastSize;
516 this.setSize(this.autoWidth ? undefined : this.getResizeEl().getWidth(), this.autoHeight ? undefined : this.getResizeEl().getHeight());
521 * Called after the component is resized, this method is empty by default but can be implemented by any
522 * subclass that needs to perform custom logic after a resize occurs.
523 * @param {Number} adjWidth The box-adjusted width that was set
524 * @param {Number} adjHeight The box-adjusted height that was set
525 * @param {Number} rawWidth The width that was originally specified
526 * @param {Number} rawHeight The height that was originally specified
528 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
529 this.fireEvent('resize', this, adjWidth, adjHeight, rawWidth, rawHeight);
533 * Called after the component is moved, this method is empty by default but can be implemented by any
534 * subclass that needs to perform custom logic after a move occurs.
535 * @param {Number} x The new x position
536 * @param {Number} y The new y position
538 onPosition : function(x, y){
543 adjustSize : function(w, h){
550 return {width : w, height: h};
554 adjustPosition : function(x, y){
555 return {x : x, y: y};
558 Ext.reg('box', Ext.BoxComponent);
561 <div id="cls-Ext.Spacer"></div>/**
563 * @extends Ext.BoxComponent
564 * <p>Used to provide a sizable space in a layout.</p>
566 * @param {Object} config
568 Ext.Spacer = Ext.extend(Ext.BoxComponent, {
571 Ext.reg('spacer', Ext.Spacer);</pre>
\r