4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-panel-AbstractPanel'>/**
19 </span> * @class Ext.panel.AbstractPanel
20 * @extends Ext.container.Container
21 * <p>A base class which provides methods common to Panel classes across the Sencha product range.</p>
22 * <p>Please refer to sub class's documentation</p>
24 Ext.define('Ext.panel.AbstractPanel', {
26 /* Begin Definitions */
28 extend: 'Ext.container.Container',
30 requires: ['Ext.util.MixedCollection', 'Ext.core.Element', 'Ext.toolbar.Toolbar'],
34 <span id='Ext-panel-AbstractPanel-cfg-baseCls'> /**
35 </span> * @cfg {String} baseCls
36 * The base CSS class to apply to this panel's element (defaults to <code>'x-panel'</code>).
38 baseCls : Ext.baseCSSPrefix + 'panel',
40 <span id='Ext-panel-AbstractPanel-cfg-bodyPadding'> /**
41 </span> * @cfg {Number/String} bodyPadding
42 * A shortcut for setting a padding style on the body element. The value can either be
43 * a number to be applied to all sides, or a normal css string describing padding.
44 * Defaults to <code>undefined</code>.
47 <span id='Ext-panel-AbstractPanel-cfg-bodyBorder'> /**
48 </span> * @cfg {Boolean} bodyBorder
49 * A shortcut to add or remove the border on the body of a panel. This only applies to a panel which has the {@link #frame} configuration set to `true`.
50 * Defaults to <code>undefined</code>.
53 <span id='Ext-panel-AbstractPanel-cfg-bodyStyle'> /**
54 </span> * @cfg {String/Object/Function} bodyStyle
55 * Custom CSS styles to be applied to the panel's body element, which can be supplied as a valid CSS style string,
56 * an object containing style property name/value pairs or a function that returns such a string or object.
57 * For example, these two formats are interpreted to be equivalent:<pre><code>
58 bodyStyle: 'background:#ffc; padding:10px;'
64 * </code></pre>
67 <span id='Ext-panel-AbstractPanel-cfg-bodyCls'> /**
68 </span> * @cfg {String/Array} bodyCls
69 * A CSS class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
70 * The following examples are all valid:<pre><code>
73 bodyCls: ['foo', 'bar']
74 * </code></pre>
79 componentLayout: 'dock',
81 <span id='Ext-panel-AbstractPanel-cfg-defaultDockWeights'> /**
82 </span> * @cfg {Object} defaultDockWeights
83 * This object holds the default weights applied to dockedItems that have no weight. These start with a
84 * weight of 1, to allow negative weights to insert before top items and are odd numbers
85 * so that even weights can be used to get between different dock orders.
87 * To make default docking order match border layout, do this:
88 * <pre><code>
89 Ext.panel.AbstractPanel.prototype.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };</code></pre>
90 * Changing these defaults as above or individually on this object will effect all Panels.
91 * To change the defaults on a single panel, you should replace the entire object:
92 * <pre><code>
93 initComponent: function () {
94 // NOTE: Don't change members of defaultDockWeights since the object is shared.
95 this.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
98 }</code></pre>
100 * To change only one of the default values, you do this:
101 * <pre><code>
102 initComponent: function () {
103 // NOTE: Don't change members of defaultDockWeights since the object is shared.
104 this.defaultDockWeights = Ext.applyIf({ top: 10 }, this.defaultDockWeights);
107 }</code></pre>
109 defaultDockWeights: { top: 1, left: 3, right: 5, bottom: 7 },
111 renderTpl: ['<div class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl> {baseCls}-body-{ui}<tpl if="uiCls"><tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl></tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>></div>'],
113 // TODO: Move code examples into product-specific files. The code snippet below is Touch only.
114 <span id='Ext-panel-AbstractPanel-cfg-dockedItems'> /**
115 </span> * @cfg {Object/Array} dockedItems
116 * A component or series of components to be added as docked items to this panel.
117 * The docked items can be docked to either the top, right, left or bottom of a panel.
118 * This is typically used for things like toolbars or tab bars:
119 * <pre><code>
120 var panel = new Ext.panel.Panel({
126 text: 'Docked to the top'
129 });</code></pre>
134 initComponent : function() {
138 <span id='Ext-panel-AbstractPanel-event-bodyresize'> /**
139 </span> * @event bodyresize
140 * Fires after the Panel has been resized.
141 * @param {Ext.panel.Panel} p the Panel which has been resized.
142 * @param {Number} width The Panel body's new width.
143 * @param {Number} height The Panel body's new height.
152 Ext.applyIf(me.renderSelectors, {
153 body: '.' + me.baseCls + '-body'
159 if (me.frame && me.border && me.bodyBorder === undefined) {
160 me.bodyBorder = false;
162 if (me.frame && me.border && (me.bodyBorder === false || me.bodyBorder === 0)) {
163 me.manageBodyBorders = true;
170 initItems : function() {
172 items = me.dockedItems;
175 me.dockedItems = Ext.create('Ext.util.MixedCollection', false, me.getComponentId);
181 <span id='Ext-panel-AbstractPanel-method-getDockedComponent'> /**
182 </span> * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
183 * @param {String/Number} comp The id, itemId or position of the docked component (see {@link #getComponent} for details)
184 * @return {Ext.Component} The docked component (if found)
186 getDockedComponent: function(comp) {
187 if (Ext.isObject(comp)) {
188 comp = comp.getItemId();
190 return this.dockedItems.get(comp);
193 <span id='Ext-panel-AbstractPanel-method-getComponent'> /**
194 </span> * Attempts a default component lookup (see {@link Ext.container.Container#getComponent}). If the component is not found in the normal
195 * items, the dockedItems are searched and the matched component (if any) returned (see {@loink #getDockedComponent}). Note that docked
196 * items will only be matched by component id or itemId -- if you pass a numeric index only non-docked child components will be searched.
197 * @param {String/Number} comp The component id, itemId or position to find
198 * @return {Ext.Component} The component (if found)
200 getComponent: function(comp) {
201 var component = this.callParent(arguments);
202 if (component === undefined && !Ext.isNumber(comp)) {
203 // If the arg is a numeric index skip docked items
204 component = this.getDockedComponent(comp);
209 <span id='Ext-panel-AbstractPanel-method-initBodyStyles'> /**
210 </span> * Parses the {@link bodyStyle} config if available to create a style string that will be applied to the body element.
211 * This also includes {@link bodyPadding} and {@link bodyBorder} if available.
212 * @return {String} A CSS style string with body styles, padding and border.
215 initBodyStyles: function() {
217 bodyStyle = me.bodyStyle,
219 Element = Ext.core.Element,
222 if (Ext.isFunction(bodyStyle)) {
223 bodyStyle = bodyStyle();
225 if (Ext.isString(bodyStyle)) {
226 styles = bodyStyle.split(';');
228 for (prop in bodyStyle) {
229 if (bodyStyle.hasOwnProperty(prop)) {
230 styles.push(prop + ':' + bodyStyle[prop]);
235 if (me.bodyPadding !== undefined) {
236 styles.push('padding: ' + Element.unitizeBox((me.bodyPadding === true) ? 5 : me.bodyPadding));
238 if (me.frame && me.bodyBorder) {
239 if (!Ext.isNumber(me.bodyBorder)) {
242 styles.push('border-width: ' + Element.unitizeBox(me.bodyBorder));
245 return styles.length ? styles.join(';') : undefined;
248 <span id='Ext-panel-AbstractPanel-method-initBodyCls'> /**
249 </span> * Parse the {@link bodyCls} config if available to create a comma-delimited string of
250 * CSS classes to be applied to the body element.
251 * @return {String} The CSS class(es)
254 initBodyCls: function() {
257 bodyCls = me.bodyCls;
260 Ext.each(bodyCls, function(v) {
261 cls += " " + v;
265 return cls.length > 0 ? cls : undefined;
268 <span id='Ext-panel-AbstractPanel-method-initRenderData'> /**
269 </span> * Initialized the renderData to be used when rendering the renderTpl.
270 * @return {Object} Object with keys and values that are going to be applied to the renderTpl
273 initRenderData: function() {
274 return Ext.applyIf(this.callParent(), {
275 bodyStyle: this.initBodyStyles(),
276 bodyCls: this.initBodyCls()
280 <span id='Ext-panel-AbstractPanel-method-addDocked'> /**
281 </span> * Adds docked item(s) to the panel.
282 * @param {Object/Array} component The Component or array of components to add. The components
283 * must include a 'dock' parameter on each component to indicate where it should be docked ('top', 'right',
285 * @param {Number} pos (optional) The index at which the Component will be added
287 addDocked : function(items, pos) {
292 items = me.prepareItems(items);
293 length = items.length;
295 for (; i < length; i++) {
297 item.dock = item.dock || 'top';
299 // Allow older browsers to target docked items to style without borders
300 if (me.border === false) {
301 // item.cls = item.cls || '' + ' ' + me.baseCls + '-noborder-docked-' + item.dock;
304 if (pos !== undefined) {
305 me.dockedItems.insert(pos + i, item);
308 me.dockedItems.add(item);
311 me.onDockedAdd(item);
314 // Set flag which means that beforeLayout will not veto the layout due to the size not changing
315 me.componentLayout.childrenChanged = true;
316 if (me.rendered && !me.suspendLayout) {
317 me.doComponentLayout();
322 // Placeholder empty functions
323 onDockedAdd : Ext.emptyFn,
324 onDockedRemove : Ext.emptyFn,
326 <span id='Ext-panel-AbstractPanel-method-insertDocked'> /**
327 </span> * Inserts docked item(s) to the panel at the indicated position.
328 * @param {Number} pos The index at which the Component will be inserted
329 * @param {Object/Array} component. The Component or array of components to add. The components
330 * must include a 'dock' paramater on each component to indicate where it should be docked ('top', 'right',
333 insertDocked : function(pos, items) {
334 this.addDocked(items, pos);
337 <span id='Ext-panel-AbstractPanel-method-removeDocked'> /**
338 </span> * Removes the docked item from the panel.
339 * @param {Ext.Component} item. The Component to remove.
340 * @param {Boolean} autoDestroy (optional) Destroy the component after removal.
342 removeDocked : function(item, autoDestroy) {
347 if (!me.dockedItems.contains(item)) {
351 layout = me.componentLayout;
352 hasLayout = layout && me.rendered;
355 layout.onRemove(item);
358 me.dockedItems.remove(item);
360 me.onDockedRemove(item);
362 if (autoDestroy === true || (autoDestroy !== false && me.autoDestroy)) {
366 if (hasLayout && !autoDestroy) {
367 layout.afterRemove(item);
371 // Set flag which means that beforeLayout will not veto the layout due to the size not changing
372 me.componentLayout.childrenChanged = true;
373 if (!me.destroying && !me.suspendLayout) {
374 me.doComponentLayout();
380 <span id='Ext-panel-AbstractPanel-method-getDockedItems'> /**
381 </span> * Retrieve an array of all currently docked Components.
382 * @param {String} cqSelector A {@link Ext.ComponentQuery ComponentQuery} selector string to filter the returned items.
383 * @return {Array} An array of components.
385 getDockedItems : function(cqSelector) {
387 defaultWeight = me.defaultDockWeights,
390 if (me.dockedItems && me.dockedItems.items.length) {
391 // Allow filtering of returned docked items by CQ selector.
393 dockedItems = Ext.ComponentQuery.query(cqSelector, me.dockedItems.items);
395 dockedItems = me.dockedItems.items.slice();
398 Ext.Array.sort(dockedItems, function(a, b) {
399 // Docked items are ordered by their visual representation by default (t,l,r,b)
400 var aw = a.weight || defaultWeight[a.dock],
401 bw = b.weight || defaultWeight[b.dock];
402 if (Ext.isNumber(aw) && Ext.isNumber(bw)) {
414 addUIClsToElement: function(cls, force) {
416 result = me.callParent(arguments),
417 classes = [Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
420 if (!force && me.rendered) {
422 me.body.addCls(me.bodyCls);
424 me.body.addCls(classes);
428 array = me.bodyCls.split(' ');
430 for (i = 0; i < classes.length; i++) {
431 if (!Ext.Array.contains(array, classes[i])) {
432 array.push(classes[i]);
436 me.bodyCls = array.join(' ');
438 me.bodyCls = classes.join(' ');
446 removeUIClsFromElement: function(cls, force) {
448 result = me.callParent(arguments),
449 classes = [Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
452 if (!force && me.rendered) {
454 me.body.removeCls(me.bodyCls);
456 me.body.removeCls(classes);
460 array = me.bodyCls.split(' ');
462 for (i = 0; i < classes.length; i++) {
463 Ext.Array.remove(array, classes[i]);
466 me.bodyCls = array.join(' ');
474 addUIToElement: function(force) {
476 cls = me.baseCls + '-body-' + me.ui,
479 me.callParent(arguments);
481 if (!force && me.rendered) {
483 me.body.addCls(me.bodyCls);
489 array = me.bodyCls.split(' ');
491 if (!Ext.Array.contains(array, cls)) {
495 me.bodyCls = array.join(' ');
503 removeUIFromElement: function() {
505 cls = me.baseCls + '-body-' + me.ui,
508 me.callParent(arguments);
512 me.body.removeCls(me.bodyCls);
514 me.body.removeCls(cls);
518 array = me.bodyCls.split(' ');
519 Ext.Array.remove(array, cls);
520 me.bodyCls = array.join(' ');
528 getTargetEl : function() {
532 getRefItems: function(deep) {
533 var items = this.callParent(arguments),
534 // deep fetches all docked items, and their descendants using '*' selector and then '* *'
535 dockedItems = this.getDockedItems(deep ? '*,* *' : undefined),
536 ln = dockedItems.length,
540 // Find the index where we go from top/left docked items to right/bottom docked items
541 for (; i < ln; i++) {
542 item = dockedItems[i];
543 if (item.dock === 'right' || item.dock === 'bottom') {
548 // Return docked items in the top/left position before our container items, and
549 // return right/bottom positioned items after our container items.
550 // See AbstractDock.renderItems() for more information.
551 return Ext.Array.splice(dockedItems, 0, i).concat(items).concat(dockedItems);
554 beforeDestroy: function(){
555 var docked = this.dockedItems,
559 while ((c = docked.first())) {
560 this.removeDocked(c, true);
566 setBorder: function(border) {
568 me.border = (border !== undefined) ? border : true;
570 me.doComponentLayout();