1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-tab.Tab'>/**
2 </span> * @author Ed Spencer
4 * @extends Ext.button.Button
6 * <p>Represents a single Tab in a {@link Ext.tab.Panel TabPanel}. A Tab is simply a slightly customized {@link Ext.button.Button Button},
7 * styled to look like a tab. Tabs are optionally closable, and can also be disabled. 99% of the time you will not
8 * need to create Tabs manually as the framework does so automatically when you use a {@link Ext.tab.Panel TabPanel}</p>
12 Ext.define('Ext.tab.Tab', {
13 extend: 'Ext.button.Button',
17 'Ext.layout.component.Tab',
21 componentLayout: 'tab',
25 baseCls: Ext.baseCSSPrefix + 'tab',
27 <span id='Ext-tab.Tab-cfg-activeCls'> /**
28 </span> * @cfg {String} activeCls
29 * The CSS class to be applied to a Tab when it is active. Defaults to 'x-tab-active'.
30 * Providing your own CSS for this class enables you to customize the active state.
34 <span id='Ext-tab.Tab-cfg-disabledCls'> /**
35 </span> * @cfg {String} disabledCls
36 * The CSS class to be applied to a Tab when it is disabled. Defaults to 'x-tab-disabled'.
39 <span id='Ext-tab.Tab-cfg-closableCls'> /**
40 </span> * @cfg {String} closableCls
41 * The CSS class which is added to the tab when it is closable
43 closableCls: 'closable',
45 <span id='Ext-tab.Tab-cfg-closable'> /**
46 </span> * @cfg {Boolean} closable True to make the Tab start closable (the close icon will be visible). Defaults to true
50 <span id='Ext-tab.Tab-cfg-closeText'> /**
51 </span> * @cfg {String} closeText
52 * The accessible text label for the close button link; only used when {@link #closable} = true.
53 * Defaults to 'Close Tab'.
55 closeText: 'Close Tab',
57 <span id='Ext-tab.Tab-property-Boolean'> /**
58 </span> * @property Boolean
59 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
63 <span id='Ext-tab.Tab-property-closable'> /**
64 </span> * @property closable
66 * True if the tab is currently closable
73 initComponent: function() {
77 <span id='Ext-tab.Tab-event-activate'> /**
78 </span> * @event activate
79 * @param {Ext.tab.Tab} this
83 <span id='Ext-tab.Tab-event-deactivate'> /**
84 </span> * @event deactivate
85 * @param {Ext.tab.Tab} this
89 <span id='Ext-tab.Tab-event-beforeclose'> /**
90 </span> * @event beforeclose
91 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
92 * false from any listener to stop the close event being fired
93 * @param {Ext.tab.Tab} tab The Tab object
97 <span id='Ext-tab.Tab-event-beforeclose'> /**
98 </span> * @event beforeclose
99 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
100 * @param {Ext.tab.Tab} tab The Tab object
105 me.callParent(arguments);
112 <span id='Ext-tab.Tab-method-onRender'> /**
115 onRender: function() {
118 me.addClsWithUI(me.position);
120 // Set all the state classNames, as they need to include the UI
121 // me.disabledCls = me.getClsWithUIs('disabled');
125 me.callParent(arguments);
131 me.syncClosableElements();
133 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
134 enter: me.onEnterKey,
141 enable : function(silent) {
144 me.callParent(arguments);
146 me.removeClsWithUI(me.position + '-disabled');
152 disable : function(silent) {
155 me.callParent(arguments);
157 me.addClsWithUI(me.position + '-disabled');
162 <span id='Ext-tab.Tab-method-onDestroy'> /**
165 onDestroy: function() {
169 me.closeEl.un('click', Ext.EventManager.preventDefault);
173 Ext.destroy(me.keyNav);
176 me.callParent(arguments);
179 <span id='Ext-tab.Tab-method-setClosable'> /**
180 </span> * Sets the tab as either closable or not
181 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
182 * close button will appear on the tab)
184 setClosable: function(closable) {
187 // Closable must be true if no args
188 closable = (!arguments.length || !!closable);
190 if (me.closable != closable) {
191 me.closable = closable;
193 // set property on the user-facing item ('card'):
195 me.card.closable = closable;
201 me.syncClosableElements();
203 // Tab will change width to accommodate close icon
204 me.doComponentLayout();
206 me.ownerCt.doLayout();
212 <span id='Ext-tab.Tab-method-syncClosableElements'> /**
213 </span> * This method ensures that the closeBtn element exists or not based on 'closable'.
216 syncClosableElements: function () {
221 me.closeEl = me.el.createChild({
223 cls: me.baseCls + '-close-btn',
227 }).on('click', Ext.EventManager.preventDefault); // mon ???
230 var closeEl = me.closeEl;
232 closeEl.un('click', Ext.EventManager.preventDefault);
239 <span id='Ext-tab.Tab-method-syncClosableUI'> /**
240 </span> * This method ensures that the UI classes are added or removed based on 'closable'.
243 syncClosableUI: function () {
244 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
247 me.addClsWithUI(classes);
249 me.removeClsWithUI(classes);
253 <span id='Ext-tab.Tab-method-setCard'> /**
254 </span> * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
255 * belongs to and would not need to be done by the developer
256 * @param {Ext.Component} card The card to set
258 setCard: function(card) {
262 me.setText(me.title || card.title);
263 me.setIconCls(me.iconCls || card.iconCls);
266 <span id='Ext-tab.Tab-method-onCloseClick'> /**
268 * Listener attached to click events on the Tab's close button
270 onCloseClick: function() {
273 if (me.fireEvent('beforeclose', me) !== false) {
275 me.tabBar.closeTab(me);
278 me.fireEvent('close', me);
282 <span id='Ext-tab.Tab-method-onEnterKey'> /**
285 onEnterKey: function(e) {
289 me.tabBar.onClick(e, me.el);
293 <span id='Ext-tab.Tab-method-onDeleteKey'> /**
296 onDeleteKey: function(e) {
305 activate : function(supressEvent) {
309 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
311 if (supressEvent !== true) {
312 me.fireEvent('activate', me);
317 deactivate : function(supressEvent) {
321 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
323 if (supressEvent !== true) {
324 me.fireEvent('deactivate', me);
328 </pre></pre></body></html>