4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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 * A base class which provides methods common to Panel classes across the Sencha product range.
24 Ext.define('Ext.panel.AbstractPanel', {
26 /* Begin Definitions */
28 extend: 'Ext.container.Container',
30 requires: ['Ext.util.MixedCollection', 'Ext.Element', 'Ext.toolbar.Toolbar'],
34 <span id='Ext-panel-AbstractPanel-cfg-baseCls'> /**
35 </span> * @cfg {String} [baseCls='x-panel']
36 * The base CSS class to apply to this panel's element.
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.
46 <span id='Ext-panel-AbstractPanel-cfg-bodyBorder'> /**
47 </span> * @cfg {Boolean} bodyBorder
48 * A shortcut to add or remove the border on the body of a panel. This only applies to a panel
49 * which has the {@link #frame} configuration set to `true`.
52 <span id='Ext-panel-AbstractPanel-cfg-bodyStyle'> /**
53 </span> * @cfg {String/Object/Function} bodyStyle
54 * Custom CSS styles to be applied to the panel's body element, which can be supplied as a valid CSS style string,
55 * an object containing style property name/value pairs or a function that returns such a string or object.
56 * For example, these two formats are interpreted to be equivalent:<pre><code>
57 bodyStyle: 'background:#ffc; padding:10px;'
63 * </code></pre>
66 <span id='Ext-panel-AbstractPanel-cfg-bodyCls'> /**
67 </span> * @cfg {String/String[]} bodyCls
68 * A CSS class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
69 * The following examples are all valid:<pre><code>
72 bodyCls: ['foo', 'bar']
73 * </code></pre>
78 componentLayout: 'dock',
80 <span id='Ext-panel-AbstractPanel-cfg-defaultDockWeights'> /**
81 </span> * @cfg {Object} defaultDockWeights
82 * This object holds the default weights applied to dockedItems that have no weight. These start with a
83 * weight of 1, to allow negative weights to insert before top items and are odd numbers
84 * so that even weights can be used to get between different dock orders.
86 * To make default docking order match border layout, do this:
87 * <pre><code>
88 Ext.panel.AbstractPanel.prototype.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };</code></pre>
89 * Changing these defaults as above or individually on this object will effect all Panels.
90 * To change the defaults on a single panel, you should replace the entire object:
91 * <pre><code>
92 initComponent: function () {
93 // NOTE: Don't change members of defaultDockWeights since the object is shared.
94 this.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
97 }</code></pre>
99 * To change only one of the default values, you do this:
100 * <pre><code>
101 initComponent: function () {
102 // NOTE: Don't change members of defaultDockWeights since the object is shared.
103 this.defaultDockWeights = Ext.applyIf({ top: 10 }, this.defaultDockWeights);
106 }</code></pre>
108 defaultDockWeights: { top: 1, left: 3, right: 5, bottom: 7 },
111 '<div id="{id}-body" class="{baseCls}-body<tpl if="bodyCls"> {bodyCls}</tpl>',
112 ' {baseCls}-body-{ui}<tpl if="uiCls">',
113 '<tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl>',
114 '</tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>>',
118 // TODO: Move code examples into product-specific files. The code snippet below is Touch only.
119 <span id='Ext-panel-AbstractPanel-cfg-dockedItems'> /**
120 </span> * @cfg {Object/Object[]} dockedItems
121 * A component or series of components to be added as docked items to this panel.
122 * The docked items can be docked to either the top, right, left or bottom of a panel.
123 * This is typically used for things like toolbars or tab bars:
124 * <pre><code>
125 var panel = new Ext.panel.Panel({
131 text: 'Docked to the top'
134 });</code></pre>
139 initComponent : function() {
143 <span id='Ext-panel-AbstractPanel-event-bodyresize'> /**
144 </span> * @event bodyresize
145 * Fires after the Panel has been resized.
146 * @param {Ext.panel.Panel} p the Panel which has been resized.
147 * @param {Number} width The Panel body's new width.
148 * @param {Number} height The Panel body's new height.
157 me.addChildEls('body');
162 if (me.frame && me.border && me.bodyBorder === undefined) {
163 me.bodyBorder = false;
165 if (me.frame && me.border && (me.bodyBorder === false || me.bodyBorder === 0)) {
166 me.manageBodyBorders = true;
173 initItems : function() {
175 items = me.dockedItems;
178 me.dockedItems = Ext.create('Ext.util.MixedCollection', false, me.getComponentId);
184 <span id='Ext-panel-AbstractPanel-method-getDockedComponent'> /**
185 </span> * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
186 * @param {String/Number} comp The id, itemId or position of the docked component (see {@link #getComponent} for details)
187 * @return {Ext.Component} The docked component (if found)
189 getDockedComponent: function(comp) {
190 if (Ext.isObject(comp)) {
191 comp = comp.getItemId();
193 return this.dockedItems.get(comp);
196 <span id='Ext-panel-AbstractPanel-method-getComponent'> /**
197 </span> * Attempts a default component lookup (see {@link Ext.container.Container#getComponent}). If the component is not found in the normal
198 * items, the dockedItems are searched and the matched component (if any) returned (see {@link #getDockedComponent}). Note that docked
199 * items will only be matched by component id or itemId -- if you pass a numeric index only non-docked child components will be searched.
200 * @param {String/Number} comp The component id, itemId or position to find
201 * @return {Ext.Component} The component (if found)
203 getComponent: function(comp) {
204 var component = this.callParent(arguments);
205 if (component === undefined && !Ext.isNumber(comp)) {
206 // If the arg is a numeric index skip docked items
207 component = this.getDockedComponent(comp);
212 <span id='Ext-panel-AbstractPanel-method-initBodyStyles'> /**
213 </span> * Parses the {@link bodyStyle} config if available to create a style string that will be applied to the body element.
214 * This also includes {@link bodyPadding} and {@link bodyBorder} if available.
215 * @return {String} A CSS style string with body styles, padding and border.
218 initBodyStyles: function() {
220 bodyStyle = me.bodyStyle,
222 Element = Ext.Element,
225 if (Ext.isFunction(bodyStyle)) {
226 bodyStyle = bodyStyle();
228 if (Ext.isString(bodyStyle)) {
229 styles = bodyStyle.split(';');
231 for (prop in bodyStyle) {
232 if (bodyStyle.hasOwnProperty(prop)) {
233 styles.push(prop + ':' + bodyStyle[prop]);
238 if (me.bodyPadding !== undefined) {
239 styles.push('padding: ' + Element.unitizeBox((me.bodyPadding === true) ? 5 : me.bodyPadding));
241 if (me.frame && me.bodyBorder) {
242 if (!Ext.isNumber(me.bodyBorder)) {
245 styles.push('border-width: ' + Element.unitizeBox(me.bodyBorder));
248 return styles.length ? styles.join(';') : undefined;
251 <span id='Ext-panel-AbstractPanel-method-initBodyCls'> /**
252 </span> * Parse the {@link bodyCls} config if available to create a comma-delimited string of
253 * CSS classes to be applied to the body element.
254 * @return {String} The CSS class(es)
257 initBodyCls: function() {
260 bodyCls = me.bodyCls;
263 Ext.each(bodyCls, function(v) {
264 cls += " " + v;
268 return cls.length > 0 ? cls : undefined;
271 <span id='Ext-panel-AbstractPanel-method-initRenderData'> /**
272 </span> * Initialized the renderData to be used when rendering the renderTpl.
273 * @return {Object} Object with keys and values that are going to be applied to the renderTpl
276 initRenderData: function() {
277 return Ext.applyIf(this.callParent(), {
278 bodyStyle: this.initBodyStyles(),
279 bodyCls: this.initBodyCls()
283 <span id='Ext-panel-AbstractPanel-method-addDocked'> /**
284 </span> * Adds docked item(s) to the panel.
285 * @param {Object/Object[]} component The Component or array of components to add. The components
286 * must include a 'dock' parameter on each component to indicate where it should be docked ('top', 'right',
288 * @param {Number} pos (optional) The index at which the Component will be added
290 addDocked : function(items, pos) {
295 items = me.prepareItems(items);
296 length = items.length;
298 for (; i < length; i++) {
300 item.dock = item.dock || 'top';
302 // Allow older browsers to target docked items to style without borders
303 if (me.border === false) {
304 // item.cls = item.cls || '' + ' ' + me.baseCls + '-noborder-docked-' + item.dock;
307 if (pos !== undefined) {
308 me.dockedItems.insert(pos + i, item);
311 me.dockedItems.add(item);
314 me.onDockedAdd(item);
317 // Set flag which means that beforeLayout will not veto the layout due to the size not changing
318 me.componentLayout.childrenChanged = true;
319 if (me.rendered && !me.suspendLayout) {
320 me.doComponentLayout();
325 // Placeholder empty functions
326 onDockedAdd : Ext.emptyFn,
327 onDockedRemove : Ext.emptyFn,
329 <span id='Ext-panel-AbstractPanel-method-insertDocked'> /**
330 </span> * Inserts docked item(s) to the panel at the indicated position.
331 * @param {Number} pos The index at which the Component will be inserted
332 * @param {Object/Object[]} component. The Component or array of components to add. The components
333 * must include a 'dock' paramater on each component to indicate where it should be docked ('top', 'right',
336 insertDocked : function(pos, items) {
337 this.addDocked(items, pos);
340 <span id='Ext-panel-AbstractPanel-method-removeDocked'> /**
341 </span> * Removes the docked item from the panel.
342 * @param {Ext.Component} item. The Component to remove.
343 * @param {Boolean} autoDestroy (optional) Destroy the component after removal.
345 removeDocked : function(item, autoDestroy) {
350 if (!me.dockedItems.contains(item)) {
354 layout = me.componentLayout;
355 hasLayout = layout && me.rendered;
358 layout.onRemove(item);
361 me.dockedItems.remove(item);
363 me.onDockedRemove(item);
365 if (autoDestroy === true || (autoDestroy !== false && me.autoDestroy)) {
367 } else if (hasLayout) {
368 // not destroying, make any layout related removals
369 layout.afterRemove(item);
373 // Set flag which means that beforeLayout will not veto the layout due to the size not changing
374 me.componentLayout.childrenChanged = true;
375 if (!me.destroying && !me.suspendLayout) {
376 me.doComponentLayout();
382 <span id='Ext-panel-AbstractPanel-method-getDockedItems'> /**
383 </span> * Retrieve an array of all currently docked Components.
384 * @param {String} cqSelector A {@link Ext.ComponentQuery ComponentQuery} selector string to filter the returned items.
385 * @return {Ext.Component[]} An array of components.
387 getDockedItems : function(cqSelector) {
389 defaultWeight = me.defaultDockWeights,
392 if (me.dockedItems && me.dockedItems.items.length) {
393 // Allow filtering of returned docked items by CQ selector.
395 dockedItems = Ext.ComponentQuery.query(cqSelector, me.dockedItems.items);
397 dockedItems = me.dockedItems.items.slice();
400 Ext.Array.sort(dockedItems, function(a, b) {
401 // Docked items are ordered by their visual representation by default (t,l,r,b)
402 var aw = a.weight || defaultWeight[a.dock],
403 bw = b.weight || defaultWeight[b.dock];
404 if (Ext.isNumber(aw) && Ext.isNumber(bw)) {
416 addUIClsToElement: function(cls, force) {
418 result = me.callParent(arguments),
419 classes = [Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
422 if (!force && me.rendered) {
424 me.body.addCls(me.bodyCls);
426 me.body.addCls(classes);
430 array = me.bodyCls.split(' ');
432 for (i = 0; i < classes.length; i++) {
433 if (!Ext.Array.contains(array, classes[i])) {
434 array.push(classes[i]);
438 me.bodyCls = array.join(' ');
440 me.bodyCls = classes.join(' ');
448 removeUIClsFromElement: function(cls, force) {
450 result = me.callParent(arguments),
451 classes = [Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls],
454 if (!force && me.rendered) {
456 me.body.removeCls(me.bodyCls);
458 me.body.removeCls(classes);
462 array = me.bodyCls.split(' ');
464 for (i = 0; i < classes.length; i++) {
465 Ext.Array.remove(array, classes[i]);
468 me.bodyCls = array.join(' ');
476 addUIToElement: function(force) {
478 cls = me.baseCls + '-body-' + me.ui,
481 me.callParent(arguments);
483 if (!force && me.rendered) {
485 me.body.addCls(me.bodyCls);
491 array = me.bodyCls.split(' ');
493 if (!Ext.Array.contains(array, cls)) {
497 me.bodyCls = array.join(' ');
505 removeUIFromElement: function() {
507 cls = me.baseCls + '-body-' + me.ui,
510 me.callParent(arguments);
514 me.body.removeCls(me.bodyCls);
516 me.body.removeCls(cls);
520 array = me.bodyCls.split(' ');
521 Ext.Array.remove(array, cls);
522 me.bodyCls = array.join(' ');
530 getTargetEl : function() {
534 getRefItems: function(deep) {
535 var items = this.callParent(arguments),
536 // deep fetches all docked items, and their descendants using '*' selector and then '* *'
537 dockedItems = this.getDockedItems(deep ? '*,* *' : undefined),
538 ln = dockedItems.length,
542 // Find the index where we go from top/left docked items to right/bottom docked items
543 for (; i < ln; i++) {
544 item = dockedItems[i];
545 if (item.dock === 'right' || item.dock === 'bottom') {
550 // Return docked items in the top/left position before our container items, and
551 // return right/bottom positioned items after our container items.
552 // See AbstractDock.renderItems() for more information.
553 return Ext.Array.splice(dockedItems, 0, i).concat(items).concat(dockedItems);
556 beforeDestroy: function(){
557 var docked = this.dockedItems,
561 while ((c = docked.first())) {
562 this.removeDocked(c, true);
568 setBorder: function(border) {
570 me.border = (border !== undefined) ? border : true;
572 me.doComponentLayout();