3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
18 * @extends Ext.panel.Header
19 * <p>TabBar is used internally by a {@link Ext.tab.Panel TabPanel} and wouldn't usually need to be created manually.</p>
21 Ext.define('Ext.tab.Bar', {
22 extend: 'Ext.panel.Header',
23 alias: 'widget.tabbar',
24 baseCls: Ext.baseCSSPrefix + 'tab-bar',
36 * True to not show the full background on the tabbar
42 '<div class="{baseCls}-body<tpl if="ui"> {baseCls}-body-{ui}<tpl for="uiCls"> {parent.baseCls}-body-{parent.ui}-{.}</tpl></tpl>"<tpl if="bodyStyle"> style="{bodyStyle}"</tpl>></div>',
43 '<div class="{baseCls}-strip<tpl if="ui"> {baseCls}-strip-{ui}<tpl for="uiCls"> {parent.baseCls}-strip-{parent.ui}-{.}</tpl></tpl>"></div>'
47 * @cfg {Number} minTabWidth The minimum width for each tab. Defaults to <tt>30</tt>.
52 * @cfg {Number} maxTabWidth The maximum width for each tab. Defaults to <tt>undefined</tt>.
54 maxTabWidth: undefined,
57 initComponent: function() {
62 me.setUI(me.ui + '-plain');
65 me.addClsWithUI(me.dock);
70 * Fired when the currently-active tab has changed
71 * @param {Ext.tab.Bar} tabBar The TabBar
72 * @param {Ext.Tab} tab The new Tab
73 * @param {Ext.Component} card The card that was just shown in the TabPanel
78 Ext.applyIf(me.renderSelectors, {
79 body : '.' + me.baseCls + '-body',
80 strip: '.' + me.baseCls + '-strip'
82 me.callParent(arguments);
84 // TabBar must override the Header's align setting.
85 me.layout.align = (me.orientation == 'vertical') ? 'left' : 'top';
86 me.layout.overflowHandler = Ext.create('Ext.layout.container.boxOverflow.Scroller', me.layout);
87 me.items.removeAt(me.items.getCount() - 1);
88 me.items.removeAt(me.items.getCount() - 1);
90 // Subscribe to Ext.FocusManager for key navigation
91 keys = me.orientation == 'vertical' ? ['up', 'down'] : ['left', 'right'];
92 Ext.FocusManager.subscribe(me, {
98 onAdd: function(tab) {
100 tabPanel = me.tabPanel,
101 hasOwner = !!tabPanel;
103 me.callParent(arguments);
104 tab.position = me.dock;
106 tab.minWidth = tabPanel.minTabWidth;
109 tab.minWidth = me.minTabWidth + (tab.iconCls ? 25 : 0);
111 tab.maxWidth = me.maxTabWidth || (hasOwner ? tabPanel.maxTabWidth : undefined);
115 afterRender: function() {
121 delegate: '.' + Ext.baseCSSPrefix + 'tab'
123 me.callParent(arguments);
127 afterComponentLayout : function() {
130 me.callParent(arguments);
131 me.strip.setWidth(me.el.getWidth());
135 onClick: function(e, target) {
136 // The target might not be a valid tab el.
137 var tab = Ext.getCmp(target.id),
138 tabPanel = this.tabPanel,
141 target = e.getTarget();
143 if (tab && tab.isDisabled && !tab.isDisabled()) {
144 if (tab.closable && target === tab.closeEl.dom) {
148 // TabPanel will card setActiveTab of the TabBar
149 tabPanel.setActiveTab(tab.card);
151 this.setActiveTab(tab);
160 * Closes the given tab by removing it from the TabBar and removing the corresponding card from the TabPanel
161 * @param {Ext.Tab} tab The tab to close
163 closeTab: function(tab) {
166 tabPanel = me.tabPanel,
169 if (card && card.fireEvent('beforeclose', card) === false) {
173 if (tab.active && me.items.getCount() > 1) {
174 nextTab = tab.next('tab') || me.items.items[0];
175 me.setActiveTab(nextTab);
177 tabPanel.setActiveTab(nextTab.card);
181 * force the close event to fire. By the time this function returns,
182 * the tab is already destroyed and all listeners have been purged
183 * so the tab can't fire itself.
188 if (tabPanel && card) {
189 card.fireEvent('close', card);
190 tabPanel.remove(card);
200 * Marks the given tab as active
201 * @param {Ext.Tab} tab The tab to mark active
203 setActiveTab: function(tab) {
209 me.activeTab.deactivate();
215 tab.el.scrollIntoView(me.layout.getRenderTarget());
218 me.fireEvent('change', me, tab, tab.card);