/ext-4.0.7/src/panel/AbstractPanel.js
JavaScript | 572 lines | 305 code | 77 blank | 190 comment | 82 complexity | 1a386d8faf8f16cfd9fdcf9f581808d0 MD5 | raw file
- /*
- This file is part of Ext JS 4
- Copyright (c) 2011 Sencha Inc
- Contact: http://www.sencha.com/contact
- GNU General Public License Usage
- This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
- If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
- */
- /**
- * @class Ext.panel.AbstractPanel
- * @extends Ext.container.Container
- * A base class which provides methods common to Panel classes across the Sencha product range.
- * @private
- */
- Ext.define('Ext.panel.AbstractPanel', {
- /* Begin Definitions */
- extend: 'Ext.container.Container',
- requires: ['Ext.util.MixedCollection', 'Ext.Element', 'Ext.toolbar.Toolbar'],
- /* End Definitions */
- /**
- * @cfg {String} [baseCls='x-panel']
- * The base CSS class to apply to this panel's element.
- */
- baseCls : Ext.baseCSSPrefix + 'panel',
- /**
- * @cfg {Number/String} bodyPadding
- * A shortcut for setting a padding style on the body element. The value can either be
- * a number to be applied to all sides, or a normal css string describing padding.
- */
- /**
- * @cfg {Boolean} bodyBorder
- * 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`.
- */
- /**
- * @cfg {String/Object/Function} bodyStyle
- * Custom CSS styles to be applied to the panel's body element, which can be supplied as a valid CSS style string,
- * an object containing style property name/value pairs or a function that returns such a string or object.
- * For example, these two formats are interpreted to be equivalent:<pre><code>
- bodyStyle: 'background:#ffc; padding:10px;'
- bodyStyle: {
- background: '#ffc',
- padding: '10px'
- }
- * </code></pre>
- */
- /**
- * @cfg {String/String[]} bodyCls
- * A CSS class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
- * The following examples are all valid:<pre><code>
- bodyCls: 'foo'
- bodyCls: 'foo bar'
- bodyCls: ['foo', 'bar']
- * </code></pre>
- */
- isPanel: true,
- componentLayout: 'dock',
- /**
- * @cfg {Object} defaultDockWeights
- * This object holds the default weights applied to dockedItems that have no weight. These start with a
- * weight of 1, to allow negative weights to insert before top items and are odd numbers
- * so that even weights can be used to get between different dock orders.
- *
- * To make default docking order match border layout, do this:
- * <pre><code>
- Ext.panel.AbstractPanel.prototype.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };</code></pre>
- * Changing these defaults as above or individually on this object will effect all Panels.
- * To change the defaults on a single panel, you should replace the entire object:
- * <pre><code>
- initComponent: function () {
- // NOTE: Don't change members of defaultDockWeights since the object is shared.
- this.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
- this.callParent();
- }</code></pre>
- *
- * To change only one of the default values, you do this:
- * <pre><code>
- initComponent: function () {
- // NOTE: Don't change members of defaultDockWeights since the object is shared.
- this.defaultDockWeights = Ext.applyIf({ top: 10 }, this.defaultDockWeights);
- this.callParent();
- }</code></pre>
- */
- defaultDockWeights: { top: 1, left: 3, right: 5, bottom: 7 },
- renderTpl: [
- '<div id="{id}-body" 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>'
- ],
- // TODO: Move code examples into product-specific files. The code snippet below is Touch only.
- /**
- * @cfg {Object/Object[]} dockedItems
- * A component or series of components to be added as docked items to this panel.
- * The docked items can be docked to either the top, right, left or bottom of a panel.
- * This is typically used for things like toolbars or tab bars:
- * <pre><code>
- var panel = new Ext.panel.Panel({
- fullscreen: true,
- dockedItems: [{
- xtype: 'toolbar',
- dock: 'top',
- items: [{
- text: 'Docked to the top'
- }]
- }]
- });</code></pre>
- */
- border: true,
- initComponent : function() {
- var me = this;
- me.addEvents(
- /**
- * @event bodyresize
- * Fires after the Panel has been resized.
- * @param {Ext.panel.Panel} p the Panel which has been resized.
- * @param {Number} width The Panel body's new width.
- * @param {Number} height The Panel body's new height.
- */
- 'bodyresize'
- // // inherited
- // 'activate',
- // // inherited
- // 'deactivate'
- );
- me.addChildEls('body');
- //!frame
- //!border
- if (me.frame && me.border && me.bodyBorder === undefined) {
- me.bodyBorder = false;
- }
- if (me.frame && me.border && (me.bodyBorder === false || me.bodyBorder === 0)) {
- me.manageBodyBorders = true;
- }
- me.callParent();
- },
- // @private
- initItems : function() {
- var me = this,
- items = me.dockedItems;
- me.callParent();
- me.dockedItems = Ext.create('Ext.util.MixedCollection', false, me.getComponentId);
- if (items) {
- me.addDocked(items);
- }
- },
- /**
- * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
- * @param {String/Number} comp The id, itemId or position of the docked component (see {@link #getComponent} for details)
- * @return {Ext.Component} The docked component (if found)
- */
- getDockedComponent: function(comp) {
- if (Ext.isObject(comp)) {
- comp = comp.getItemId();
- }
- return this.dockedItems.get(comp);
- },
- /**
- * Attempts a default component lookup (see {@link Ext.container.Container#getComponent}). If the component is not found in the normal
- * items, the dockedItems are searched and the matched component (if any) returned (see {@link #getDockedComponent}). Note that docked
- * items will only be matched by component id or itemId -- if you pass a numeric index only non-docked child components will be searched.
- * @param {String/Number} comp The component id, itemId or position to find
- * @return {Ext.Component} The component (if found)
- */
- getComponent: function(comp) {
- var component = this.callParent(arguments);
- if (component === undefined && !Ext.isNumber(comp)) {
- // If the arg is a numeric index skip docked items
- component = this.getDockedComponent(comp);
- }
- return component;
- },
- /**
- * Parses the {@link bodyStyle} config if available to create a style string that will be applied to the body element.
- * This also includes {@link bodyPadding} and {@link bodyBorder} if available.
- * @return {String} A CSS style string with body styles, padding and border.
- * @private
- */
- initBodyStyles: function() {
- var me = this,
- bodyStyle = me.bodyStyle,
- styles = [],
- Element = Ext.Element,
- prop;
- if (Ext.isFunction(bodyStyle)) {
- bodyStyle = bodyStyle();
- }
- if (Ext.isString(bodyStyle)) {
- styles = bodyStyle.split(';');
- } else {
- for (prop in bodyStyle) {
- if (bodyStyle.hasOwnProperty(prop)) {
- styles.push(prop + ':' + bodyStyle[prop]);
- }
- }
- }
- if (me.bodyPadding !== undefined) {
- styles.push('padding: ' + Element.unitizeBox((me.bodyPadding === true) ? 5 : me.bodyPadding));
- }
- if (me.frame && me.bodyBorder) {
- if (!Ext.isNumber(me.bodyBorder)) {
- me.bodyBorder = 1;
- }
- styles.push('border-width: ' + Element.unitizeBox(me.bodyBorder));
- }
- delete me.bodyStyle;
- return styles.length ? styles.join(';') : undefined;
- },
-