4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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. Typically 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>
27 Ext.define('Ext.tab.Tab', {
28 extend: 'Ext.button.Button',
32 'Ext.layout.component.Tab',
36 componentLayout: 'tab',
40 baseCls: Ext.baseCSSPrefix + 'tab',
42 <span id='Ext-tab-Tab-cfg-activeCls'> /**
43 </span> * @cfg {String} activeCls
44 * The CSS class to be applied to a Tab when it is active.
45 * Providing your own CSS for this class enables you to customize the active state.
49 <span id='Ext-tab-Tab-cfg-disabledCls'> /**
50 </span> * @cfg {String} disabledCls
51 * The CSS class to be applied to a Tab when it is disabled.
54 <span id='Ext-tab-Tab-cfg-closableCls'> /**
55 </span> * @cfg {String} closableCls
56 * The CSS class which is added to the tab when it is closable
58 closableCls: 'closable',
60 <span id='Ext-tab-Tab-cfg-closable'> /**
61 </span> * @cfg {Boolean} closable True to make the Tab start closable (the close icon will be visible).
65 <span id='Ext-tab-Tab-cfg-closeText'> /**
66 </span> * @cfg {String} closeText
67 * The accessible text label for the close button link; only used when {@link #closable} = true.
69 closeText: 'Close Tab',
71 <span id='Ext-tab-Tab-property-active'> /**
72 </span> * @property {Boolean} active
73 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
77 <span id='Ext-tab-Tab-property-closable'> /**
78 </span> * @property closable
80 * True if the tab is currently closable
87 initComponent: function() {
91 <span id='Ext-tab-Tab-event-activate'> /**
92 </span> * @event activate
93 * Fired when the tab is activated.
94 * @param {Ext.tab.Tab} this
98 <span id='Ext-tab-Tab-event-deactivate'> /**
99 </span> * @event deactivate
100 * Fired when the tab is deactivated.
101 * @param {Ext.tab.Tab} this
105 <span id='Ext-tab-Tab-event-beforeclose'> /**
106 </span> * @event beforeclose
107 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
108 * false from any listener to stop the close event being fired
109 * @param {Ext.tab.Tab} tab The Tab object
113 <span id='Ext-tab-Tab-event-close'> /**
114 </span> * @event close
115 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
116 * @param {Ext.tab.Tab} tab The Tab object
121 me.callParent(arguments);
128 <span id='Ext-tab-Tab-method-onRender'> /**
131 onRender: function() {
133 tabBar = me.up('tabbar'),
134 tabPanel = me.up('tabpanel');
136 me.addClsWithUI(me.position);
138 // Set all the state classNames, as they need to include the UI
139 // me.disabledCls = me.getClsWithUIs('disabled');
143 // Propagate minTabWidth and maxTabWidth settings from the owning TabBar then TabPanel
145 me.minWidth = (tabBar) ? tabBar.minTabWidth : me.minWidth;
146 if (!me.minWidth && tabPanel) {
147 me.minWidth = tabPanel.minTabWidth;
149 if (me.minWidth && me.iconCls) {
154 me.maxWidth = (tabBar) ? tabBar.maxTabWidth : me.maxWidth;
155 if (!me.maxWidth && tabPanel) {
156 me.maxWidth = tabPanel.maxTabWidth;
160 me.callParent(arguments);
166 me.syncClosableElements();
168 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
169 enter: me.onEnterKey,
176 enable : function(silent) {
179 me.callParent(arguments);
181 me.removeClsWithUI(me.position + '-disabled');
187 disable : function(silent) {
190 me.callParent(arguments);
192 me.addClsWithUI(me.position + '-disabled');
197 <span id='Ext-tab-Tab-method-onDestroy'> /**
200 onDestroy: function() {
204 me.closeEl.un('click', Ext.EventManager.preventDefault);
208 Ext.destroy(me.keyNav);
211 me.callParent(arguments);
214 <span id='Ext-tab-Tab-method-setClosable'> /**
215 </span> * Sets the tab as either closable or not
216 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
217 * close button will appear on the tab)
219 setClosable: function(closable) {
222 // Closable must be true if no args
223 closable = (!arguments.length || !!closable);
225 if (me.closable != closable) {
226 me.closable = closable;
228 // set property on the user-facing item ('card'):
230 me.card.closable = closable;
236 me.syncClosableElements();
238 // Tab will change width to accommodate close icon
239 me.doComponentLayout();
241 me.ownerCt.doLayout();
247 <span id='Ext-tab-Tab-method-syncClosableElements'> /**
248 </span> * This method ensures that the closeBtn element exists or not based on 'closable'.
251 syncClosableElements: function () {
256 me.closeEl = me.el.createChild({
258 cls: me.baseCls + '-close-btn',
260 // html: me.closeText, // removed for EXTJSIV-1719, by rob@sencha.com
262 }).on('click', Ext.EventManager.preventDefault); // mon ???
265 var closeEl = me.closeEl;
267 closeEl.un('click', Ext.EventManager.preventDefault);
274 <span id='Ext-tab-Tab-method-syncClosableUI'> /**
275 </span> * This method ensures that the UI classes are added or removed based on 'closable'.
278 syncClosableUI: function () {
279 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
282 me.addClsWithUI(classes);
284 me.removeClsWithUI(classes);
288 <span id='Ext-tab-Tab-method-setCard'> /**
289 </span> * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
290 * belongs to and would not need to be done by the developer
291 * @param {Ext.Component} card The card to set
293 setCard: function(card) {
297 me.setText(me.title || card.title);
298 me.setIconCls(me.iconCls || card.iconCls);
301 <span id='Ext-tab-Tab-method-onCloseClick'> /**
303 * Listener attached to click events on the Tab's close button
305 onCloseClick: function() {
308 if (me.fireEvent('beforeclose', me) !== false) {
310 if (me.tabBar.closeTab(me) === false) {
311 // beforeclose on the panel vetoed the event, stop here
315 // if there's no tabbar, fire the close event
316 me.fireEvent('close', me);
321 <span id='Ext-tab-Tab-method-fireClose'> /**
322 </span> * Fires the close event on the tab.
325 fireClose: function(){
326 this.fireEvent('close', this);
329 <span id='Ext-tab-Tab-method-onEnterKey'> /**
332 onEnterKey: function(e) {
336 me.tabBar.onClick(e, me.el);
340 <span id='Ext-tab-Tab-method-onDeleteKey'> /**
343 onDeleteKey: function(e) {
352 activate : function(supressEvent) {
356 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
358 if (supressEvent !== true) {
359 me.fireEvent('activate', me);
364 deactivate : function(supressEvent) {
368 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
370 if (supressEvent !== true) {
371 me.fireEvent('deactivate', me);