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.button.Button
20 * <p>Represents a single Tab in a {@link Ext.tab.Panel TabPanel}. A Tab is simply a slightly customized {@link Ext.button.Button Button},
21 * styled to look like a tab. Tabs are optionally closable, and can also be disabled. 99% of the time you will not
22 * need to create Tabs manually as the framework does so automatically when you use a {@link Ext.tab.Panel TabPanel}</p>
24 Ext.define('Ext.tab.Tab', {
25 extend: 'Ext.button.Button',
29 'Ext.layout.component.Tab',
33 componentLayout: 'tab',
37 baseCls: Ext.baseCSSPrefix + 'tab',
40 * @cfg {String} activeCls
41 * The CSS class to be applied to a Tab when it is active. Defaults to 'x-tab-active'.
42 * Providing your own CSS for this class enables you to customize the active state.
47 * @cfg {String} disabledCls
48 * The CSS class to be applied to a Tab when it is disabled. Defaults to 'x-tab-disabled'.
52 * @cfg {String} closableCls
53 * The CSS class which is added to the tab when it is closable
55 closableCls: 'closable',
58 * @cfg {Boolean} closable True to make the Tab start closable (the close icon will be visible). Defaults to true
63 * @cfg {String} closeText
64 * The accessible text label for the close button link; only used when {@link #closable} = true.
65 * Defaults to 'Close Tab'.
67 closeText: 'Close Tab',
71 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
78 * True if the tab is currently closable
85 initComponent: function() {
91 * @param {Ext.tab.Tab} this
97 * @param {Ext.tab.Tab} this
103 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
104 * false from any listener to stop the close event being fired
105 * @param {Ext.tab.Tab} tab The Tab object
111 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
112 * @param {Ext.tab.Tab} tab The Tab object
117 me.callParent(arguments);
127 onRender: function() {
130 me.addClsWithUI(me.position);
132 // Set all the state classNames, as they need to include the UI
133 // me.disabledCls = me.getClsWithUIs('disabled');
137 me.callParent(arguments);
143 me.syncClosableElements();
145 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
146 enter: me.onEnterKey,
153 enable : function(silent) {
156 me.callParent(arguments);
158 me.removeClsWithUI(me.position + '-disabled');
164 disable : function(silent) {
167 me.callParent(arguments);
169 me.addClsWithUI(me.position + '-disabled');
177 onDestroy: function() {
181 me.closeEl.un('click', Ext.EventManager.preventDefault);
185 Ext.destroy(me.keyNav);
188 me.callParent(arguments);
192 * Sets the tab as either closable or not
193 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
194 * close button will appear on the tab)
196 setClosable: function(closable) {
199 // Closable must be true if no args
200 closable = (!arguments.length || !!closable);
202 if (me.closable != closable) {
203 me.closable = closable;
205 // set property on the user-facing item ('card'):
207 me.card.closable = closable;
213 me.syncClosableElements();
215 // Tab will change width to accommodate close icon
216 me.doComponentLayout();
218 me.ownerCt.doLayout();
225 * This method ensures that the closeBtn element exists or not based on 'closable'.
228 syncClosableElements: function () {
233 me.closeEl = me.el.createChild({
235 cls: me.baseCls + '-close-btn',
237 // html: me.closeText, // removed for EXTJSIV-1719, by rob@sencha.com
239 }).on('click', Ext.EventManager.preventDefault); // mon ???
242 var closeEl = me.closeEl;
244 closeEl.un('click', Ext.EventManager.preventDefault);
252 * This method ensures that the UI classes are added or removed based on 'closable'.
255 syncClosableUI: function () {
256 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
259 me.addClsWithUI(classes);
261 me.removeClsWithUI(classes);
266 * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
267 * belongs to and would not need to be done by the developer
268 * @param {Ext.Component} card The card to set
270 setCard: function(card) {
274 me.setText(me.title || card.title);
275 me.setIconCls(me.iconCls || card.iconCls);
280 * Listener attached to click events on the Tab's close button
282 onCloseClick: function() {
285 if (me.fireEvent('beforeclose', me) !== false) {
287 if (me.tabBar.closeTab(me) === false) {
288 // beforeclose on the panel vetoed the event, stop here
292 // if there's no tabbar, fire the close event
293 me.fireEvent('close', me);
299 * Fires the close event on the tab.
302 fireClose: function(){
303 this.fireEvent('close', this);
309 onEnterKey: function(e) {
313 me.tabBar.onClick(e, me.el);
320 onDeleteKey: function(e) {
329 activate : function(supressEvent) {
333 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
335 if (supressEvent !== true) {
336 me.fireEvent('activate', me);
341 deactivate : function(supressEvent) {
345 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
347 if (supressEvent !== true) {
348 me.fireEvent('deactivate', me);