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-method-constructor'><span id='Ext-panel-AbstractPanel'>/**
19 </span></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 * @param {Object} config The config object
26 Ext.define('Ext.panel.AbstractPanel', {
28 /* Begin Definitions */
30 extend: 'Ext.container.Container',
32 requires: ['Ext.util.MixedCollection', 'Ext.core.Element', 'Ext.toolbar.Toolbar'],
36 <span id='Ext-panel-AbstractPanel-cfg-baseCls'> /**
37 </span> * @cfg {String} baseCls
38 * The base CSS class to apply to this panel's element (defaults to <code>'x-panel'</code>).
40 baseCls : Ext.baseCSSPrefix + 'panel',
42 <span id='Ext-panel-AbstractPanel-cfg-bodyPadding'> /**
43 </span> * @cfg {Number/String} bodyPadding
44 * A shortcut for setting a padding style on the body element. The value can either be
45 * a number to be applied to all sides, or a normal css string describing padding.
46 * Defaults to <code>undefined</code>.
49 <span id='Ext-panel-AbstractPanel-cfg-bodyBorder'> /**
50 </span> * @cfg {Boolean} bodyBorder
51 * 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`.
52 * Defaults to <code>undefined</code>.
55 <span id='Ext-panel-AbstractPanel-cfg-bodyStyle'> /**
56 </span> * @cfg {String/Object/Function} bodyStyle
57 * Custom CSS styles to be applied to the panel's body element, which can be supplied as a valid CSS style string,
58 * an object containing style property name/value pairs or a function that returns such a string or object.
59 * For example, these two formats are interpreted to be equivalent:<pre><code>
60 bodyStyle: 'background:#ffc; padding:10px;'
66 * </code></pre>
69 <span id='Ext-panel-AbstractPanel-cfg-bodyCls'> /**
70 </span> * @cfg {String/Array} bodyCls
71 * A CSS class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
72 * The following examples are all valid:<pre><code>
75 bodyCls: ['foo', 'bar']
76 * </code></pre>
81 componentLayout: 'dock',
83 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>'],
85 // TODO: Move code examples into product-specific files. The code snippet below is Touch only.
86 <span id='Ext-panel-AbstractPanel-cfg-dockedItems'> /**
87 </span> * @cfg {Object/Array} dockedItems
88 * A component or series of components to be added as docked items to this panel.
89 * The docked items can be docked to either the top, right, left or bottom of a panel.
90 * This is typically used for things like toolbars or tab bars:
91 * <pre><code>
92 var panel = new Ext.panel.Panel({
98 text: 'Docked to the top'
101 });</code></pre>
106 initComponent : function() {
110 <span id='Ext-panel-AbstractPanel-event-bodyresize'> /**
111 </span> * @event bodyresize
112 * Fires after the Panel has been resized.
113 * @param {Ext.panel.Panel} p the Panel which has been resized.
114 * @param {Number} width The Panel body's new width.
115 * @param {Number} height The Panel body's new height.
124 Ext.applyIf(me.renderSelectors, {
125 body: '.' + me.baseCls + '-body'
131 if (me.frame && me.border && me.bodyBorder === undefined) {
132 me.bodyBorder = false;
134 if (me.frame && me.border && (me.bodyBorder === false || me.bodyBorder === 0)) {
135 me.manageBodyBorders = true;
142 initItems : function() {
144 items = me.dockedItems;
147 me.dockedItems = Ext.create('Ext.util.MixedCollection', false, me.getComponentId);
153 <span id='Ext-panel-AbstractPanel-method-getDockedComponent'> /**
154 </span> * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
155 * @param {String/Number} comp The id, itemId or position of the docked component (see {@link #getComponent} for details)
156 * @return {Ext.Component} The docked component (if found)
158 getDockedComponent: function(comp) {
159 if (Ext.isObject(comp)) {
160 comp = comp.getItemId();
162 return this.dockedItems.get(comp);
165 <span id='Ext-panel-AbstractPanel-method-getComponent'> /**
166 </span> * Attempts a default component lookup (see {@link Ext.container.Container#getComponent}). If the component is not found in the normal
167 * items, the dockedItems are searched and the matched component (if any) returned (see {@loink #getDockedComponent}). Note that docked
168 * items will only be matched by component id or itemId -- if you pass a numeric index only non-docked child components will be searched.
169 * @param {String/Number} comp The component id, itemId or position to find
170 * @return {Ext.Component} The component (if found)
172 getComponent: function(comp) {
173 var component = this.callParent(arguments);
174 if (component === undefined && !Ext.isNumber(comp)) {
175 // If the arg is a numeric index skip docked items
176 component = this.getDockedComponent(comp);
181 <span id='Ext-panel-AbstractPanel-method-initBodyStyles'> /**
182 </span> * Parses the {@link bodyStyle} config if available to create a style string that will be applied to the body element.
183 * This also includes {@link bodyPadding} and {@link bodyBorder} if available.
184 * @return {String} A CSS style string with body styles, padding and border.
187 initBodyStyles: function() {
189 bodyStyle = me.bodyStyle,
191 Element = Ext.core.Element,
194 if (Ext.isFunction(bodyStyle)) {
195 bodyStyle = bodyStyle();
197 if (Ext.isString(bodyStyle)) {
198 styles = bodyStyle.split(';');
200 for (prop in bodyStyle) {
201 if (bodyStyle.hasOwnProperty(prop)) {
202 styles.push(prop + ':' + bodyStyle[prop]);
207 if (me.bodyPadding !== undefined) {
208 styles.push('padding: ' + Element.unitizeBox((me.bodyPadding === true) ? 5 : me.bodyPadding));
210 if (me.frame && me.bodyBorder) {
211 if (!Ext.isNumber(me.bodyBorder)) {
214 styles.push('border-width: ' + Element.unitizeBox(me.bodyBorder));
217 return styles.length ? styles.join(';') : undefined;
220 <span id='Ext-panel-AbstractPanel-method-initBodyCls'> /**
221 </span> * Parse the {@link bodyCls} config if available to create a comma-delimited string of
222 * CSS classes to be applied to the body element.
223 * @return {String} The CSS class(es)
226 initBodyCls: function() {
229 bodyCls = me.bodyCls;
232 Ext.each(bodyCls, function(v) {
233 cls += " " + v;
237 return cls.length > 0 ? cls : undefined;
240 <span id='Ext-panel-AbstractPanel-method-initRenderData'> /**
241 </span> * Initialized the renderData to be used when rendering the renderTpl.
242 * @return {Object} Object with keys and values that are going to be applied to the renderTpl
245 initRenderData: function() {
246 return Ext.applyIf(this.callParent(), {
247 bodyStyle: this.initBodyStyles(),
248 bodyCls: this.initBodyCls()
252 <span id='Ext-panel-AbstractPanel-method-addDocked'> /**
253 </span> * Adds docked item(s) to the panel.
254 * @param {Object/Array} component The Component or array of components to add. The components
255 * must include a 'dock' parameter on each component to indicate where it should be docked ('top', 'right',
257 * @param {Number} pos (optional) The index at which the Component will be added
259 addDocked : function(items, pos) {
264 items = me.prepareItems(items);
265 length = items.length;
267 for (; i < length; i++) {
269 item.dock = item.dock || 'top';
271 // Allow older browsers to target docked items to style without borders
272 if (me.border === false) {
273 // item.cls = item.cls || '' + ' ' + me.baseCls + '-noborder-docked-' + item.dock;
276 if (pos !== undefined) {
277 me.dockedItems.insert(pos + i, item);
280 me.dockedItems.add(item);
283 me.onDockedAdd(item);
285 if (me.rendered && !me.suspendLayout) {
286 me.doComponentLayout();
291 // Placeholder empty functions
292 onDockedAdd : Ext.emptyFn,
293 onDockedRemove : Ext.emptyFn,
295 <span id='Ext-panel-AbstractPanel-method-insertDocked'> /**
296 </span> * Inserts docked item(s) to the panel at the indicated position.
297 * @param {Number} pos The index at which the Component will be inserted
298 * @param {Object/Array} component. The Component or array of components to add. The components
299 * must include a 'dock' paramater on each component to indicate where it should be docked ('top', 'right',
302 insertDocked : function(pos, items) {
303 this.addDocked(items, pos);
306 <span id='Ext-panel-AbstractPanel-method-removeDocked'> /**
307 </span> * Removes the docked item from the panel.
308 * @param {Ext.Component} item. The Component to remove.
309 * @param {Boolean} autoDestroy (optional) Destroy the component after removal.
311 removeDocked : function(item, autoDestroy) {
316 if (!me.dockedItems.contains(item)) {
320 layout = me.componentLayout;
321 hasLayout = layout && me.rendered;
324 layout.onRemove(item);
327 me.dockedItems.remove(item);
329 me.onDockedRemove(item);
331 if (autoDestroy === true || (autoDestroy !== false && me.autoDestroy)) {
335 if (hasLayout && !autoDestroy) {
336 layout.afterRemove(item);
339 if (!this.destroying) {
340 me.doComponentLayout();
346 <span id='Ext-panel-AbstractPanel-method-getDockedItems'> /**
347 </span> * Retrieve an array of all currently docked Components.
348 * @param {String} cqSelector A {@link Ext.ComponentQuery ComponentQuery} selector string to filter the returned items.
349 * @return {Array} An array of components.
351 getDockedItems : function(cqSelector) {
353 // Start with a weight of 1, so users can provide <= 0 to come before top items
354 // Odd numbers, so users can provide a weight to come in between if desired
355 defaultWeight = { top: 1, left: 3, right: 5, bottom: 7 },
358 if (me.dockedItems && me.dockedItems.items.length) {
359 // Allow filtering of returned docked items by CQ selector.
361 dockedItems = Ext.ComponentQuery.query(cqSelector, me.dockedItems.items);
363 dockedItems = me.dockedItems.items.slice();
366 Ext.Array.sort(dockedItems, function(a, b) {
367 // Docked items are ordered by their visual representation by default (t,l,r,b)
368 // TODO: Enforce position ordering, and have weights be sub-ordering within positions?
369 var aw = a.weight || defaultWeight[a.dock],
370 bw = b.weight || defaultWeight[b.dock];
371 if (Ext.isNumber(aw) && Ext.isNumber(bw)) {
383 addUIClsToElement: function(cls, force) {
386 me.callParent(arguments);
388 if (!force && me.rendered) {
389 me.body.addCls(Ext.baseCSSPrefix + cls);
390 me.body.addCls(me.baseCls + '-body-' + cls);
391 me.body.addCls(me.baseCls + '-body-' + me.ui + '-' + cls);
396 removeUIClsFromElement: function(cls, force) {
399 me.callParent(arguments);
401 if (!force && me.rendered) {
402 me.body.removeCls(Ext.baseCSSPrefix + cls);
403 me.body.removeCls(me.baseCls + '-body-' + cls);
404 me.body.removeCls(me.baseCls + '-body-' + me.ui + '-' + cls);
409 addUIToElement: function(force) {
412 me.callParent(arguments);
414 if (!force && me.rendered) {
415 me.body.addCls(me.baseCls + '-body-' + me.ui);
420 removeUIFromElement: function() {
423 me.callParent(arguments);
426 me.body.removeCls(me.baseCls + '-body-' + me.ui);
431 getTargetEl : function() {
435 getRefItems: function(deep) {
436 var items = this.callParent(arguments),
437 // deep fetches all docked items, and their descendants using '*' selector and then '* *'
438 dockedItems = this.getDockedItems(deep ? '*,* *' : undefined),
439 ln = dockedItems.length,
443 // Find the index where we go from top/left docked items to right/bottom docked items
444 for (; i < ln; i++) {
445 item = dockedItems[i];
446 if (item.dock === 'right' || item.dock === 'bottom') {
451 // Return docked items in the top/left position before our container items, and
452 // return right/bottom positioned items after our container items.
453 // See AbstractDock.renderItems() for more information.
454 return dockedItems.splice(0, i).concat(items).concat(dockedItems);
457 beforeDestroy: function(){
458 var docked = this.dockedItems,
462 while ((c = docked.first())) {
463 this.removeDocked(c, true);
469 setBorder: function(border) {
471 me.border = (border !== undefined) ? border : true;
473 me.doComponentLayout();