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>
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. Defaults to 'x-tab-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. Defaults to 'x-tab-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). Defaults to true
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.
68 * Defaults to 'Close Tab'.
70 closeText: 'Close Tab',
72 <span id='Ext-tab-Tab-property-Boolean'> /**
73 </span> * @property Boolean
74 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
78 <span id='Ext-tab-Tab-property-closable'> /**
79 </span> * @property closable
81 * True if the tab is currently closable
88 initComponent: function() {
92 <span id='Ext-tab-Tab-event-activate'> /**
93 </span> * @event activate
94 * @param {Ext.tab.Tab} this
98 <span id='Ext-tab-Tab-event-deactivate'> /**
99 </span> * @event deactivate
100 * @param {Ext.tab.Tab} this
104 <span id='Ext-tab-Tab-event-beforeclose'> /**
105 </span> * @event beforeclose
106 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
107 * false from any listener to stop the close event being fired
108 * @param {Ext.tab.Tab} tab The Tab object
112 <span id='Ext-tab-Tab-event-beforeclose'> /**
113 </span> * @event beforeclose
114 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
115 * @param {Ext.tab.Tab} tab The Tab object
120 me.callParent(arguments);
127 <span id='Ext-tab-Tab-method-onRender'> /**
130 onRender: function() {
133 me.addClsWithUI(me.position);
135 // Set all the state classNames, as they need to include the UI
136 // me.disabledCls = me.getClsWithUIs('disabled');
140 me.callParent(arguments);
146 me.syncClosableElements();
148 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
149 enter: me.onEnterKey,
156 enable : function(silent) {
159 me.callParent(arguments);
161 me.removeClsWithUI(me.position + '-disabled');
167 disable : function(silent) {
170 me.callParent(arguments);
172 me.addClsWithUI(me.position + '-disabled');
177 <span id='Ext-tab-Tab-method-onDestroy'> /**
180 onDestroy: function() {
184 me.closeEl.un('click', Ext.EventManager.preventDefault);
188 Ext.destroy(me.keyNav);
191 me.callParent(arguments);
194 <span id='Ext-tab-Tab-method-setClosable'> /**
195 </span> * Sets the tab as either closable or not
196 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
197 * close button will appear on the tab)
199 setClosable: function(closable) {
202 // Closable must be true if no args
203 closable = (!arguments.length || !!closable);
205 if (me.closable != closable) {
206 me.closable = closable;
208 // set property on the user-facing item ('card'):
210 me.card.closable = closable;
216 me.syncClosableElements();
218 // Tab will change width to accommodate close icon
219 me.doComponentLayout();
221 me.ownerCt.doLayout();
227 <span id='Ext-tab-Tab-method-syncClosableElements'> /**
228 </span> * This method ensures that the closeBtn element exists or not based on 'closable'.
231 syncClosableElements: function () {
236 me.closeEl = me.el.createChild({
238 cls: me.baseCls + '-close-btn',
240 // html: me.closeText, // removed for EXTJSIV-1719, by rob@sencha.com
242 }).on('click', Ext.EventManager.preventDefault); // mon ???
245 var closeEl = me.closeEl;
247 closeEl.un('click', Ext.EventManager.preventDefault);
254 <span id='Ext-tab-Tab-method-syncClosableUI'> /**
255 </span> * This method ensures that the UI classes are added or removed based on 'closable'.
258 syncClosableUI: function () {
259 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
262 me.addClsWithUI(classes);
264 me.removeClsWithUI(classes);
268 <span id='Ext-tab-Tab-method-setCard'> /**
269 </span> * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
270 * belongs to and would not need to be done by the developer
271 * @param {Ext.Component} card The card to set
273 setCard: function(card) {
277 me.setText(me.title || card.title);
278 me.setIconCls(me.iconCls || card.iconCls);
281 <span id='Ext-tab-Tab-method-onCloseClick'> /**
283 * Listener attached to click events on the Tab's close button
285 onCloseClick: function() {
288 if (me.fireEvent('beforeclose', me) !== false) {
290 if (me.tabBar.closeTab(me) === false) {
291 // beforeclose on the panel vetoed the event, stop here
295 // if there's no tabbar, fire the close event
296 me.fireEvent('close', me);
301 <span id='Ext-tab-Tab-method-fireClose'> /**
302 </span> * Fires the close event on the tab.
305 fireClose: function(){
306 this.fireEvent('close', this);
309 <span id='Ext-tab-Tab-method-onEnterKey'> /**
312 onEnterKey: function(e) {
316 me.tabBar.onClick(e, me.el);
320 <span id='Ext-tab-Tab-method-onDeleteKey'> /**
323 onDeleteKey: function(e) {
332 activate : function(supressEvent) {
336 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
338 if (supressEvent !== true) {
339 me.fireEvent('activate', me);
344 deactivate : function(supressEvent) {
348 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
350 if (supressEvent !== true) {
351 me.fireEvent('deactivate', me);