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-tab-Tab'>/**
19 </span> * @author Ed Spencer
21 * @extends Ext.button.Button
23 * <p>Represents a single Tab in a {@link Ext.tab.Panel TabPanel}. A Tab is simply a slightly customized {@link Ext.button.Button Button},
24 * styled to look like a tab. Tabs are optionally closable, and can also be disabled. 99% of the time you will not
25 * need to create Tabs manually as the framework does so automatically when you use a {@link Ext.tab.Panel TabPanel}</p>
29 Ext.define('Ext.tab.Tab', {
30 extend: 'Ext.button.Button',
34 'Ext.layout.component.Tab',
38 componentLayout: 'tab',
42 baseCls: Ext.baseCSSPrefix + 'tab',
44 <span id='Ext-tab-Tab-cfg-activeCls'> /**
45 </span> * @cfg {String} activeCls
46 * The CSS class to be applied to a Tab when it is active. Defaults to 'x-tab-active'.
47 * Providing your own CSS for this class enables you to customize the active state.
51 <span id='Ext-tab-Tab-cfg-disabledCls'> /**
52 </span> * @cfg {String} disabledCls
53 * The CSS class to be applied to a Tab when it is disabled. Defaults to 'x-tab-disabled'.
56 <span id='Ext-tab-Tab-cfg-closableCls'> /**
57 </span> * @cfg {String} closableCls
58 * The CSS class which is added to the tab when it is closable
60 closableCls: 'closable',
62 <span id='Ext-tab-Tab-cfg-closable'> /**
63 </span> * @cfg {Boolean} closable True to make the Tab start closable (the close icon will be visible). Defaults to true
67 <span id='Ext-tab-Tab-cfg-closeText'> /**
68 </span> * @cfg {String} closeText
69 * The accessible text label for the close button link; only used when {@link #closable} = true.
70 * Defaults to 'Close Tab'.
72 closeText: 'Close Tab',
74 <span id='Ext-tab-Tab-property-Boolean'> /**
75 </span> * @property Boolean
76 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
80 <span id='Ext-tab-Tab-property-closable'> /**
81 </span> * @property closable
83 * True if the tab is currently closable
90 initComponent: function() {
94 <span id='Ext-tab-Tab-event-activate'> /**
95 </span> * @event activate
96 * @param {Ext.tab.Tab} this
100 <span id='Ext-tab-Tab-event-deactivate'> /**
101 </span> * @event deactivate
102 * @param {Ext.tab.Tab} this
106 <span id='Ext-tab-Tab-event-beforeclose'> /**
107 </span> * @event beforeclose
108 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
109 * false from any listener to stop the close event being fired
110 * @param {Ext.tab.Tab} tab The Tab object
114 <span id='Ext-tab-Tab-event-beforeclose'> /**
115 </span> * @event beforeclose
116 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
117 * @param {Ext.tab.Tab} tab The Tab object
122 me.callParent(arguments);
129 <span id='Ext-tab-Tab-method-onRender'> /**
132 onRender: function() {
135 me.addClsWithUI(me.position);
137 // Set all the state classNames, as they need to include the UI
138 // me.disabledCls = me.getClsWithUIs('disabled');
142 me.callParent(arguments);
148 me.syncClosableElements();
150 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
151 enter: me.onEnterKey,
158 enable : function(silent) {
161 me.callParent(arguments);
163 me.removeClsWithUI(me.position + '-disabled');
169 disable : function(silent) {
172 me.callParent(arguments);
174 me.addClsWithUI(me.position + '-disabled');
179 <span id='Ext-tab-Tab-method-onDestroy'> /**
182 onDestroy: function() {
186 me.closeEl.un('click', Ext.EventManager.preventDefault);
190 Ext.destroy(me.keyNav);
193 me.callParent(arguments);
196 <span id='Ext-tab-Tab-method-setClosable'> /**
197 </span> * Sets the tab as either closable or not
198 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
199 * close button will appear on the tab)
201 setClosable: function(closable) {
204 // Closable must be true if no args
205 closable = (!arguments.length || !!closable);
207 if (me.closable != closable) {
208 me.closable = closable;
210 // set property on the user-facing item ('card'):
212 me.card.closable = closable;
218 me.syncClosableElements();
220 // Tab will change width to accommodate close icon
221 me.doComponentLayout();
223 me.ownerCt.doLayout();
229 <span id='Ext-tab-Tab-method-syncClosableElements'> /**
230 </span> * This method ensures that the closeBtn element exists or not based on 'closable'.
233 syncClosableElements: function () {
238 me.closeEl = me.el.createChild({
240 cls: me.baseCls + '-close-btn',
244 }).on('click', Ext.EventManager.preventDefault); // mon ???
247 var closeEl = me.closeEl;
249 closeEl.un('click', Ext.EventManager.preventDefault);
256 <span id='Ext-tab-Tab-method-syncClosableUI'> /**
257 </span> * This method ensures that the UI classes are added or removed based on 'closable'.
260 syncClosableUI: function () {
261 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
264 me.addClsWithUI(classes);
266 me.removeClsWithUI(classes);
270 <span id='Ext-tab-Tab-method-setCard'> /**
271 </span> * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
272 * belongs to and would not need to be done by the developer
273 * @param {Ext.Component} card The card to set
275 setCard: function(card) {
279 me.setText(me.title || card.title);
280 me.setIconCls(me.iconCls || card.iconCls);
283 <span id='Ext-tab-Tab-method-onCloseClick'> /**
285 * Listener attached to click events on the Tab's close button
287 onCloseClick: function() {
290 if (me.fireEvent('beforeclose', me) !== false) {
292 if (me.tabBar.closeTab(me) === false) {
293 // beforeclose on the panel vetoed the event, stop here
297 // if there's no tabbar, fire the close event
298 me.fireEvent('close', me);
303 <span id='Ext-tab-Tab-method-fireClose'> /**
304 </span> * Fires the close event on the tab.
307 fireClose: function(){
308 this.fireEvent('close', this);
311 <span id='Ext-tab-Tab-method-onEnterKey'> /**
314 onEnterKey: function(e) {
318 me.tabBar.onClick(e, me.el);
322 <span id='Ext-tab-Tab-method-onDeleteKey'> /**
325 onDeleteKey: function(e) {
334 activate : function(supressEvent) {
338 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
340 if (supressEvent !== true) {
341 me.fireEvent('activate', me);
346 deactivate : function(supressEvent) {
350 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
352 if (supressEvent !== true) {
353 me.fireEvent('deactivate', me);