3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.TabPanel"></div>/**
17 * <p>A basic tab container. TabPanels can be used exactly like a standard {@link Ext.Panel}
18 * for layout purposes, but also have special support for containing child Components
19 * (<tt>{@link Ext.Container#items items}</tt>) that are managed using a
20 * {@link Ext.layout.CardLayout CardLayout layout manager}, and displayed as separate tabs.</p>
22 * <b>Note:</b> By default, a tab's close tool <i>destroys</i> the child tab Component
23 * and all its descendants. This makes the child tab Component, and all its descendants <b>unusable</b>. To enable
24 * re-use of a tab, configure the TabPanel with <b><code>{@link #autoDestroy autoDestroy: false}</code></b>.
26 * <p><b><u>TabPanel header/footer elements</u></b></p>
27 * <p>TabPanels use their {@link Ext.Panel#header header} or {@link Ext.Panel#footer footer} element
28 * (depending on the {@link #tabPosition} configuration) to accommodate the tab selector buttons.
29 * This means that a TabPanel will not display any configured title, and will not display any
30 * configured header {@link Ext.Panel#tools tools}.</p>
31 * <p>To display a header, embed the TabPanel in a {@link Ext.Panel Panel} which uses
32 * <b><tt>{@link Ext.Container#layout layout:'fit'}</tt></b>.</p>
34 * <p><b><u>Tab Events</u></b></p>
35 * <p>There is no actual tab class — each tab is simply a {@link Ext.BoxComponent Component}
36 * such as a {@link Ext.Panel Panel}. However, when rendered in a TabPanel, each child Component
37 * can fire additional events that only exist for tabs and are not available from other Components.
38 * These events are:</p>
39 * <div><ul class="mdetail-params">
40 * <li><tt><b>{@link Ext.Panel#activate activate}</b></tt> : Fires when this Component becomes
41 * the active tab.</li>
42 * <li><tt><b>{@link Ext.Panel#deactivate deactivate}</b></tt> : Fires when the Component that
43 * was the active tab becomes deactivated.</li>
44 * <li><tt><b>{@link Ext.Panel#beforeclose beforeclose}</b></tt> : Fires when the user clicks on the close tool of a closeable tab.
45 * May be vetoed by returning <code>false</code> from a handler.</li>
46 * <li><tt><b>{@link Ext.Panel#close close}</b></tt> : Fires a closeable tab has been closed by the user.</li>
48 * <p><b><u>Creating TabPanels from Code</u></b></p>
49 * <p>TabPanels can be created and rendered completely in code, as in this example:</p>
51 var tabs = new Ext.TabPanel({
52 renderTo: Ext.getBody(),
63 * <p><b><u>Creating TabPanels from Existing Markup</u></b></p>
64 * <p>TabPanels can also be rendered from pre-existing markup in a couple of ways.</p>
65 * <div><ul class="mdetail-params">
67 * <li>Pre-Structured Markup</li>
68 * <div class="sub-desc">
69 * <p>A container div with one or more nested tab divs with class <tt>'x-tab'</tt> can be rendered entirely
70 * from existing markup (See the {@link #autoTabs} example).</p>
73 * <li>Un-Structured Markup</li>
74 * <div class="sub-desc">
75 * <p>A TabPanel can also be rendered from markup that is not strictly structured by simply specifying by id
76 * which elements should be the container and the tabs. Using this method tab content can be pulled from different
77 * elements within the page by id regardless of page structure. For example:</p>
79 var tabs = new Ext.TabPanel({
83 {contentEl:'tab1', title:'Tab 1'},
84 {contentEl:'tab2', title:'Tab 2'}
88 // Note that the tabs do not have to be nested within the container (although they can be)
89 <div id="my-tabs"></div>
90 <div id="tab1" class="x-hide-display">A simple tab</div>
91 <div id="tab2" class="x-hide-display">Another one</div>
93 * Note that the tab divs in this example contain the class <tt>'x-hide-display'</tt> so that they can be rendered
94 * deferred without displaying outside the tabs. You could alternately set <tt>{@link #deferredRender} = false </tt>
95 * to render all content tabs on page load.
102 * @param {Object} config The configuration options
105 Ext.TabPanel = Ext.extend(Ext.Panel, {
106 <div id="cfg-Ext.TabPanel-layoutOnTabChange"></div>/**
107 * @cfg {Boolean} layoutOnTabChange
108 * Set to true to force a layout of the active tab when the tab is changed. Defaults to false.
109 * See {@link Ext.layout.CardLayout}.<code>{@link Ext.layout.CardLayout#layoutOnCardChange layoutOnCardChange}</code>.
111 <div id="cfg-Ext.TabPanel-tabCls"></div>/**
112 * @cfg {String} tabCls <b>This config option is used on <u>child Components</u> of ths TabPanel.</b> A CSS
113 * class name applied to the tab strip item representing the child Component, allowing special
114 * styling to be applied.
116 <div id="cfg-Ext.TabPanel-deferredRender"></div>/**
117 * @cfg {Boolean} deferredRender
118 * <p><tt>true</tt> by default to defer the rendering of child <tt>{@link Ext.Container#items items}</tt>
119 * to the browsers DOM until a tab is activated. <tt>false</tt> will render all contained
120 * <tt>{@link Ext.Container#items items}</tt> as soon as the {@link Ext.layout.CardLayout layout}
121 * is rendered. If there is a significant amount of content or a lot of heavy controls being
122 * rendered into panels that are not displayed by default, setting this to <tt>true</tt> might
123 * improve performance.</p>
124 * <br><p>The <tt>deferredRender</tt> property is internally passed to the layout manager for
125 * TabPanels ({@link Ext.layout.CardLayout}) as its {@link Ext.layout.CardLayout#deferredRender}
126 * configuration value.</p>
127 * <br><p><b>Note</b>: leaving <tt>deferredRender</tt> as <tt>true</tt> means that the content
128 * within an unactivated tab will not be available. For example, this means that if the TabPanel
129 * is within a {@link Ext.form.FormPanel form}, then until a tab is activated, any Fields within
130 * unactivated tabs will not be rendered, and will therefore not be submitted and will not be
131 * available to either {@link Ext.form.BasicForm#getValues getValues} or
132 * {@link Ext.form.BasicForm#setValues setValues}.</p>
134 deferredRender : true,
135 <div id="cfg-Ext.TabPanel-tabWidth"></div>/**
136 * @cfg {Number} tabWidth The initial width in pixels of each new tab (defaults to 120).
139 <div id="cfg-Ext.TabPanel-minTabWidth"></div>/**
140 * @cfg {Number} minTabWidth The minimum width in pixels for each tab when {@link #resizeTabs} = true (defaults to 30).
143 <div id="cfg-Ext.TabPanel-resizeTabs"></div>/**
144 * @cfg {Boolean} resizeTabs True to automatically resize each tab so that the tabs will completely fill the
145 * tab strip (defaults to false). Setting this to true may cause specific widths that might be set per tab to
146 * be overridden in order to fit them all into view (although {@link #minTabWidth} will always be honored).
149 <div id="cfg-Ext.TabPanel-enableTabScroll"></div>/**
150 * @cfg {Boolean} enableTabScroll True to enable scrolling to tabs that may be invisible due to overflowing the
151 * overall TabPanel width. Only available with tabPosition:'top' (defaults to false).
153 enableTabScroll : false,
154 <div id="cfg-Ext.TabPanel-scrollIncrement"></div>/**
155 * @cfg {Number} scrollIncrement The number of pixels to scroll each time a tab scroll button is pressed
156 * (defaults to <tt>100</tt>, or if <tt>{@link #resizeTabs} = true</tt>, the calculated tab width). Only
157 * applies when <tt>{@link #enableTabScroll} = true</tt>.
160 <div id="cfg-Ext.TabPanel-scrollRepeatInterval"></div>/**
161 * @cfg {Number} scrollRepeatInterval Number of milliseconds between each scroll while a tab scroll button is
162 * continuously pressed (defaults to <tt>400</tt>).
164 scrollRepeatInterval : 400,
165 <div id="cfg-Ext.TabPanel-scrollDuration"></div>/**
166 * @cfg {Float} scrollDuration The number of milliseconds that each scroll animation should last (defaults
167 * to <tt>.35</tt>). Only applies when <tt>{@link #animScroll} = true</tt>.
169 scrollDuration : 0.35,
170 <div id="cfg-Ext.TabPanel-animScroll"></div>/**
171 * @cfg {Boolean} animScroll True to animate tab scrolling so that hidden tabs slide smoothly into view (defaults
172 * to <tt>true</tt>). Only applies when <tt>{@link #enableTabScroll} = true</tt>.
175 <div id="cfg-Ext.TabPanel-tabPosition"></div>/**
176 * @cfg {String} tabPosition The position where the tab strip should be rendered (defaults to <tt>'top'</tt>).
177 * The only other supported value is <tt>'bottom'</tt>. <b>Note</b>: tab scrolling is only supported for
178 * <tt>tabPosition: 'top'</tt>.
181 <div id="cfg-Ext.TabPanel-baseCls"></div>/**
182 * @cfg {String} baseCls The base CSS class applied to the panel (defaults to <tt>'x-tab-panel'</tt>).
184 baseCls : 'x-tab-panel',
185 <div id="cfg-Ext.TabPanel-autoTabs"></div>/**
186 * @cfg {Boolean} autoTabs
187 * <p><tt>true</tt> to query the DOM for any divs with a class of 'x-tab' to be automatically converted
188 * to tabs and added to this panel (defaults to <tt>false</tt>). Note that the query will be executed within
189 * the scope of the container element only (so that multiple tab panels from markup can be supported via this
191 * <p>This method is only possible when the markup is structured correctly as a container with nested divs
192 * containing the class <tt>'x-tab'</tt>. To create TabPanels without these limitations, or to pull tab content
193 * from other elements on the page, see the example at the top of the class for generating tabs from markup.</p>
194 * <p>There are a couple of things to note when using this method:<ul>
195 * <li>When using the <tt>autoTabs</tt> config (as opposed to passing individual tab configs in the TabPanel's
196 * {@link #items} collection), you must use <tt>{@link #applyTo}</tt> to correctly use the specified <tt>id</tt>
197 * as the tab container. The <tt>autoTabs</tt> method <em>replaces</em> existing content with the TabPanel
199 * <li>Make sure that you set <tt>{@link #deferredRender}: false</tt> so that the content elements for each
200 * tab will be rendered into the TabPanel immediately upon page load, otherwise they will not be transformed
201 * until each tab is activated and will be visible outside the TabPanel.</li>
202 * </ul>Example usage:</p>
204 var tabs = new Ext.TabPanel({
207 deferredRender: false,
211 // This markup will be converted to a TabPanel from the code above
212 <div id="my-tabs">
213 <div class="x-tab" title="Tab 1">A simple tab</div>
214 <div class="x-tab" title="Tab 2">Another one</div>
219 <div id="cfg-Ext.TabPanel-autoTabSelector"></div>/**
220 * @cfg {String} autoTabSelector The CSS selector used to search for tabs in existing markup when
221 * <tt>{@link #autoTabs} = true</tt> (defaults to <tt>'div.x-tab'</tt>). This can be any valid selector
222 * supported by {@link Ext.DomQuery#select}. Note that the query will be executed within the scope of this
223 * tab panel only (so that multiple tab panels from markup can be supported on a page).
225 autoTabSelector : 'div.x-tab',
226 <div id="cfg-Ext.TabPanel-activeTab"></div>/**
227 * @cfg {String/Number} activeTab A string id or the numeric index of the tab that should be initially
228 * activated on render (defaults to undefined).
230 activeTab : undefined,
231 <div id="cfg-Ext.TabPanel-tabMargin"></div>/**
232 * @cfg {Number} tabMargin The number of pixels of space to calculate into the sizing and scrolling of
233 * tabs. If you change the margin in CSS, you will need to update this value so calculations are correct
234 * with either <tt>{@link #resizeTabs}</tt> or scrolling tabs. (defaults to <tt>2</tt>)
237 <div id="cfg-Ext.TabPanel-plain"></div>/**
238 * @cfg {Boolean} plain </tt>true</tt> to render the tab strip without a background container image
239 * (defaults to <tt>false</tt>).
242 <div id="cfg-Ext.TabPanel-wheelIncrement"></div>/**
243 * @cfg {Number} wheelIncrement For scrolling tabs, the number of pixels to increment on mouse wheel
244 * scrolling (defaults to <tt>20</tt>).
249 * This is a protected property used when concatenating tab ids to the TabPanel id for internal uniqueness.
250 * It does not generally need to be changed, but can be if external code also uses an id scheme that can
251 * potentially clash with this one.
256 itemCls : 'x-tab-item',
258 // private config overrides
260 headerAsText : false,
265 initComponent : function(){
267 Ext.TabPanel.superclass.initComponent.call(this);
269 <div id="event-Ext.TabPanel-beforetabchange"></div>/**
270 * @event beforetabchange
271 * Fires before the active tab changes. Handlers can <tt>return false</tt> to cancel the tab change.
272 * @param {TabPanel} this
273 * @param {Panel} newTab The tab being activated
274 * @param {Panel} currentTab The current active tab
277 <div id="event-Ext.TabPanel-tabchange"></div>/**
279 * Fires after the active tab has changed.
280 * @param {TabPanel} this
281 * @param {Panel} tab The new active tab
284 <div id="event-Ext.TabPanel-contextmenu"></div>/**
286 * Relays the contextmenu event from a tab selector element in the tab strip.
287 * @param {TabPanel} this
288 * @param {Panel} tab The target tab
289 * @param {EventObject} e
293 <div id="cfg-Ext.TabPanel-layoutConfig"></div>/**
294 * @cfg {Object} layoutConfig
295 * TabPanel implicitly uses {@link Ext.layout.CardLayout} as its layout manager.
296 * <code>layoutConfig</code> may be used to configure this layout manager.
297 * <code>{@link #deferredRender}</code> and <code>{@link #layoutOnTabChange}</code>
298 * configured on the TabPanel will be applied as configs to the layout manager.
300 this.setLayout(new Ext.layout.CardLayout(Ext.apply({
301 layoutOnCardChange: this.layoutOnTabChange,
302 deferredRender: this.deferredRender
303 }, this.layoutConfig)));
305 if(this.tabPosition == 'top'){
306 this.elements += ',header';
307 this.stripTarget = 'header';
309 this.elements += ',footer';
310 this.stripTarget = 'footer';
313 this.stack = Ext.TabPanel.AccessStack();
319 onRender : function(ct, position){
320 Ext.TabPanel.superclass.onRender.call(this, ct, position);
323 var pos = this.tabPosition == 'top' ? 'header' : 'footer';
324 this[pos].addClass('x-tab-panel-'+pos+'-plain');
327 var st = this[this.stripTarget];
329 this.stripWrap = st.createChild({cls:'x-tab-strip-wrap', cn:{
330 tag:'ul', cls:'x-tab-strip x-tab-strip-'+this.tabPosition}});
332 var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
333 st.createChild({cls:'x-tab-strip-spacer'}, beforeEl);
334 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
336 // create an empty span with class x-tab-strip-text to force the height of the header element when there's no tabs.
337 this.edge = this.strip.createChild({tag:'li', cls:'x-tab-edge', cn: [{tag: 'span', cls: 'x-tab-strip-text', cn: ' '}]});
338 this.strip.createChild({cls:'x-clear'});
340 this.body.addClass('x-tab-panel-body-'+this.tabPosition);
342 <div id="cfg-Ext.TabPanel-itemTpl"></div>/**
343 * @cfg {Template/XTemplate} itemTpl <p>(Optional) A {@link Ext.Template Template} or
344 * {@link Ext.XTemplate XTemplate} which may be provided to process the data object returned from
345 * <tt>{@link #getTemplateArgs}</tt> to produce a clickable selector element in the tab strip.</p>
346 * <p>The main element created should be a <tt><li></tt> element. In order for a click event on
347 * a selector element to be connected to its item, it must take its <i>id</i> from the TabPanel's
348 * native <tt>{@link #getTemplateArgs}</tt>.</p>
349 * <p>The child element which contains the title text must be marked by the CSS class
350 * <tt>x-tab-strip-inner</tt>.</p>
351 * <p>To enable closability, the created element should contain an element marked by the CSS class
352 * <tt>x-tab-strip-close</tt>.</p>
353 * <p>If a custom <tt>itemTpl</tt> is supplied, it is the developer's responsibility to create CSS
354 * style rules to create the desired appearance.</p>
355 * Below is an example of how to create customized tab selector items:<pre><code>
357 renderTo: document.body,
360 enableTabScroll: true,
363 defaults: {autoScroll:true},
364 itemTpl: new Ext.XTemplate(
365 '<li class="{cls}" id="{id}" style="overflow:hidden">',
366 '<tpl if="closable">',
367 '<a class="x-tab-strip-close"></a>',
369 '<a class="x-tab-right" href="#" style="padding-left:6px">',
370 '<em class="x-tab-left">',
371 '<span class="x-tab-strip-inner">',
372 '<img src="{src}" style="float:left;margin:3px 3px 0 0">',
373 '<span style="margin-left:20px" class="x-tab-strip-text {iconCls}">{text} {extra}</span>',
379 getTemplateArgs: function(item) {
380 // Call the native method to collect the base data. Like the ID!
381 var result = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
383 // Add stuff used in our template
384 return Ext.apply(result, {
385 closable: item.closable,
387 extra: item.extraText || ''
392 iconSrc: '../shared/icons/fam/grid.png',
397 iconSrc: '../shared/icons/fam/grid.png',
399 extraText: 'Extra stuff in the tab button'
405 var tt = new Ext.Template(
406 '<li class="{cls}" id="{id}"><a class="x-tab-strip-close"></a>',
407 '<a class="x-tab-right" href="#"><em class="x-tab-left">',
408 '<span class="x-tab-strip-inner"><span class="x-tab-strip-text {iconCls}">{text}</span></span>',
411 tt.disableFormats = true;
413 Ext.TabPanel.prototype.itemTpl = tt;
416 this.items.each(this.initTab, this);
420 afterRender : function(){
421 Ext.TabPanel.superclass.afterRender.call(this);
423 this.readTabs(false);
425 if(this.activeTab !== undefined){
426 var item = Ext.isObject(this.activeTab) ? this.activeTab : this.items.get(this.activeTab);
427 delete this.activeTab;
428 this.setActiveTab(item);
433 initEvents : function(){
434 Ext.TabPanel.superclass.initEvents.call(this);
435 this.mon(this.strip, {
437 mousedown: this.onStripMouseDown,
438 contextmenu: this.onStripContextMenu
440 if(this.enableTabScroll){
441 this.mon(this.strip, 'mousewheel', this.onWheel, this);
446 findTargets : function(e){
448 itemEl = e.getTarget('li:not(.x-tab-edge)', this.strip);
451 item = this.getComponent(itemEl.id.split(this.idDelimiter)[1]);
461 close : e.getTarget('.x-tab-strip-close', this.strip),
468 onStripMouseDown : function(e){
473 var t = this.findTargets(e);
475 if (t.item.fireEvent('beforeclose', t.item) !== false) {
476 t.item.fireEvent('close', t.item);
481 if(t.item && t.item != this.activeTab){
482 this.setActiveTab(t.item);
487 onStripContextMenu : function(e){
489 var t = this.findTargets(e);
491 this.fireEvent('contextmenu', this, t.item, e);
495 <div id="method-Ext.TabPanel-readTabs"></div>/**
496 * True to scan the markup in this tab panel for <tt>{@link #autoTabs}</tt> using the
497 * <tt>{@link #autoTabSelector}</tt>
498 * @param {Boolean} removeExisting True to remove existing tabs
500 readTabs : function(removeExisting){
501 if(removeExisting === true){
502 this.items.each(function(item){
506 var tabs = this.el.query(this.autoTabSelector);
507 for(var i = 0, len = tabs.length; i < len; i++){
509 title = tab.getAttribute('title');
510 tab.removeAttribute('title');
519 initTab : function(item, index){
520 var before = this.strip.dom.childNodes[index],
521 p = this.getTemplateArgs(item),
523 this.itemTpl.insertBefore(before, p) :
524 this.itemTpl.append(this.strip, p),
525 cls = 'x-tab-strip-over',
528 tabEl.hover(function(){
533 tabEl.removeClass(cls);
537 tabEl.child('span.x-tab-strip-text', true).qtip = item.tabTip;
541 // Route *keyboard triggered* click events to the tab strip mouse handler.
542 tabEl.select('a').on('click', function(e){
544 this.onStripMouseDown(e);
546 }, this, {preventDefault: true});
550 disable: this.onItemDisabled,
551 enable: this.onItemEnabled,
552 titlechange: this.onItemTitleChanged,
553 iconchange: this.onItemIconChanged,
554 beforeshow: this.onBeforeShowItem
560 <div id="method-Ext.TabPanel-getTemplateArgs"></div>/**
561 * <p>Provides template arguments for rendering a tab selector item in the tab strip.</p>
562 * <p>This method returns an object hash containing properties used by the TabPanel's <tt>{@link #itemTpl}</tt>
563 * to create a formatted, clickable tab selector element. The properties which must be returned
564 * are:</p><div class="mdetail-params"><ul>
565 * <li><b>id</b> : String<div class="sub-desc">A unique identifier which links to the item</div></li>
566 * <li><b>text</b> : String<div class="sub-desc">The text to display</div></li>
567 * <li><b>cls</b> : String<div class="sub-desc">The CSS class name</div></li>
568 * <li><b>iconCls</b> : String<div class="sub-desc">A CSS class to provide appearance for an icon.</div></li>
570 * @param {Ext.BoxComponent} item The {@link Ext.BoxComponent BoxComponent} for which to create a selector element in the tab strip.
571 * @return {Object} An object hash containing the properties required to render the selector element.
573 getTemplateArgs : function(item) {
574 var cls = item.closable ? 'x-tab-strip-closable' : '';
576 cls += ' x-item-disabled';
579 cls += ' x-tab-with-icon';
582 cls += ' ' + item.tabCls;
586 id: this.id + this.idDelimiter + item.getItemId(),
589 iconCls: item.iconCls || ''
595 Ext.TabPanel.superclass.onAdd.call(this, c);
597 var items = this.items;
598 this.initTab(c, items.indexOf(c));
599 this.delegateUpdates();
604 onBeforeAdd : function(item){
605 var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
607 this.setActiveTab(item);
610 Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
611 var es = item.elements;
612 item.elements = es ? es.replace(',header', '') : es;
613 item.border = (item.border === true);
617 onRemove : function(c){
618 var te = Ext.get(c.tabEl);
619 // check if the tabEl exists, it won't if the tab isn't rendered
621 te.select('a').removeAllListeners();
624 Ext.TabPanel.superclass.onRemove.call(this, c);
625 this.stack.remove(c);
627 c.un('disable', this.onItemDisabled, this);
628 c.un('enable', this.onItemEnabled, this);
629 c.un('titlechange', this.onItemTitleChanged, this);
630 c.un('iconchange', this.onItemIconChanged, this);
631 c.un('beforeshow', this.onBeforeShowItem, this);
632 if(c == this.activeTab){
633 var next = this.stack.next();
635 this.setActiveTab(next);
636 }else if(this.items.getCount() > 0){
637 this.setActiveTab(0);
639 this.setActiveTab(null);
642 if(!this.destroying){
643 this.delegateUpdates();
648 onBeforeShowItem : function(item){
649 if(item != this.activeTab){
650 this.setActiveTab(item);
656 onItemDisabled : function(item){
657 var el = this.getTabEl(item);
659 Ext.fly(el).addClass('x-item-disabled');
661 this.stack.remove(item);
665 onItemEnabled : function(item){
666 var el = this.getTabEl(item);
668 Ext.fly(el).removeClass('x-item-disabled');
673 onItemTitleChanged : function(item){
674 var el = this.getTabEl(item);
676 Ext.fly(el).child('span.x-tab-strip-text', true).innerHTML = item.title;
681 onItemIconChanged : function(item, iconCls, oldCls){
682 var el = this.getTabEl(item);
685 el.child('span.x-tab-strip-text').replaceClass(oldCls, iconCls);
686 el[Ext.isEmpty(iconCls) ? 'removeClass' : 'addClass']('x-tab-with-icon');
690 <div id="method-Ext.TabPanel-getTabEl"></div>/**
691 * Gets the DOM element for the tab strip item which activates the child panel with the specified
692 * ID. Access this to change the visual treatment of the item, for example by changing the CSS class name.
693 * @param {Panel/Number/String} tab The tab component, or the tab's index, or the tabs id or itemId.
694 * @return {HTMLElement} The DOM node
696 getTabEl : function(item){
697 var c = this.getComponent(item);
698 return c ? c.tabEl : null;
702 onResize : function(){
703 Ext.TabPanel.superclass.onResize.apply(this, arguments);
704 this.delegateUpdates();
707 <div id="method-Ext.TabPanel-beginUpdate"></div>/**
708 * Suspends any internal calculations or scrolling while doing a bulk operation. See {@link #endUpdate}
710 beginUpdate : function(){
711 this.suspendUpdates = true;
714 <div id="method-Ext.TabPanel-endUpdate"></div>/**
715 * Resumes calculations and scrolling at the end of a bulk operation. See {@link #beginUpdate}
717 endUpdate : function(){
718 this.suspendUpdates = false;
719 this.delegateUpdates();
722 <div id="method-Ext.TabPanel-hideTabStripItem"></div>/**
723 * Hides the tab strip item for the passed tab
724 * @param {Number/String/Panel} item The tab index, id or item
726 hideTabStripItem : function(item){
727 item = this.getComponent(item);
728 var el = this.getTabEl(item);
730 el.style.display = 'none';
731 this.delegateUpdates();
733 this.stack.remove(item);
736 <div id="method-Ext.TabPanel-unhideTabStripItem"></div>/**
737 * Unhides the tab strip item for the passed tab
738 * @param {Number/String/Panel} item The tab index, id or item
740 unhideTabStripItem : function(item){
741 item = this.getComponent(item);
742 var el = this.getTabEl(item);
744 el.style.display = '';
745 this.delegateUpdates();
750 delegateUpdates : function(){
751 var rendered = this.rendered;
752 if(this.suspendUpdates){
755 if(this.resizeTabs && rendered){
758 if(this.enableTabScroll && rendered){
759 this.autoScrollTabs();
764 autoSizeTabs : function(){
765 var count = this.items.length,
766 ce = this.tabPosition != 'bottom' ? 'header' : 'footer',
767 ow = this[ce].dom.offsetWidth,
768 aw = this[ce].dom.clientWidth;
770 if(!this.resizeTabs || count < 1 || !aw){ // !aw for display:none
774 var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.tabMargin, this.tabWidth), this.minTabWidth); // -4 for float errors in IE
775 this.lastTabWidth = each;
776 var lis = this.strip.query('li:not(.x-tab-edge)');
777 for(var i = 0, len = lis.length; i < len; i++) {
779 inner = Ext.fly(li).child('.x-tab-strip-inner', true),
781 iw = inner.offsetWidth;
782 inner.style.width = (each - (tw-iw)) + 'px';
787 adjustBodyWidth : function(w){
789 this.header.setWidth(w);
792 this.footer.setWidth(w);
797 <div id="method-Ext.TabPanel-setActiveTab"></div>/**
798 * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
799 * can <tt>return false</tt> to cancel the tab change.
800 * @param {String/Number} item
801 * The id or tab Panel to activate. This parameter may be any of the following:
802 * <div><ul class="mdetail-params">
803 * <li>a <b><tt>String</tt></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
804 * or <code>{@link Ext.Component#id id}</code> of the child component </li>
805 * <li>a <b><tt>Number</tt></b> : representing the position of the child component
806 * within the <code>{@link Ext.Container#items items}</code> <b>property</b></li>
808 * <p>For additional information see {@link Ext.util.MixedCollection#get}.
810 setActiveTab : function(item){
811 item = this.getComponent(item);
812 if(this.fireEvent('beforetabchange', this, item, this.activeTab) === false){
816 this.activeTab = item;
819 if(this.activeTab != item){
821 var oldEl = this.getTabEl(this.activeTab);
823 Ext.fly(oldEl).removeClass('x-tab-strip-active');
826 this.activeTab = item;
828 var el = this.getTabEl(item);
829 Ext.fly(el).addClass('x-tab-strip-active');
830 this.stack.add(item);
832 this.layout.setActiveItem(item);
833 // Need to do this here, since setting the active tab slightly changes the size
834 this.delegateUpdates();
836 this.scrollToTab(item, this.animScroll);
839 this.fireEvent('tabchange', this, item);
843 <div id="method-Ext.TabPanel-getActiveTab"></div>/**
844 * Returns the Component which is the currently active tab. <b>Note that before the TabPanel
845 * first activates a child Component, this method will return whatever was configured in the
846 * {@link #activeTab} config option.</b>
847 * @return {BoxComponent} The currently active child Component if one <i>is</i> active, or the {@link #activeTab} config value.
849 getActiveTab : function(){
850 return this.activeTab || null;
853 <div id="method-Ext.TabPanel-getItem"></div>/**
854 * Gets the specified tab by id.
855 * @param {String} id The tab id
856 * @return {Panel} The tab
858 getItem : function(item){
859 return this.getComponent(item);
863 autoScrollTabs : function(){
864 this.pos = this.tabPosition=='bottom' ? this.footer : this.header;
865 var count = this.items.length,
866 ow = this.pos.dom.offsetWidth,
867 tw = this.pos.dom.clientWidth,
868 wrap = this.stripWrap,
871 pos = this.getScrollPos(),
872 l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
874 if(!this.enableTabScroll || cw < 20){ // 20 to prevent display:none issues
877 if(count == 0 || l <= tw){
878 // ensure the width is set if there's no tabs
882 this.scrolling = false;
883 this.pos.removeClass('x-tab-scrolling');
884 this.scrollLeft.hide();
885 this.scrollRight.hide();
886 // See here: http://extjs.com/forum/showthread.php?t=49308&highlight=isSafari
887 if(Ext.isAir || Ext.isWebKit){
888 wd.style.marginLeft = '';
889 wd.style.marginRight = '';
894 this.pos.addClass('x-tab-scrolling');
895 // See here: http://extjs.com/forum/showthread.php?t=49308&highlight=isSafari
896 if(Ext.isAir || Ext.isWebKit){
897 wd.style.marginLeft = '18px';
898 wd.style.marginRight = '18px';
901 tw -= wrap.getMargins('lr');
902 wrap.setWidth(tw > 20 ? tw : 20);
904 if(!this.scrollLeft){
905 this.createScrollers();
907 this.scrollLeft.show();
908 this.scrollRight.show();
911 this.scrolling = true;
912 if(pos > (l-tw)){ // ensure it stays within bounds
913 wd.scrollLeft = l-tw;
914 }else{ // otherwise, make sure the active tab is still visible
915 this.scrollToTab(this.activeTab, false);
917 this.updateScrollButtons();
922 createScrollers : function(){
923 this.pos.addClass('x-tab-scrolling-' + this.tabPosition);
924 var h = this.stripWrap.dom.offsetHeight;
927 var sl = this.pos.insertFirst({
928 cls:'x-tab-scroller-left'
931 sl.addClassOnOver('x-tab-scroller-left-over');
932 this.leftRepeater = new Ext.util.ClickRepeater(sl, {
933 interval : this.scrollRepeatInterval,
934 handler: this.onScrollLeft,
937 this.scrollLeft = sl;
940 var sr = this.pos.insertFirst({
941 cls:'x-tab-scroller-right'
944 sr.addClassOnOver('x-tab-scroller-right-over');
945 this.rightRepeater = new Ext.util.ClickRepeater(sr, {
946 interval : this.scrollRepeatInterval,
947 handler: this.onScrollRight,
950 this.scrollRight = sr;
954 getScrollWidth : function(){
955 return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
959 getScrollPos : function(){
960 return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
964 getScrollArea : function(){
965 return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
969 getScrollAnim : function(){
970 return {duration:this.scrollDuration, callback: this.updateScrollButtons, scope: this};
974 getScrollIncrement : function(){
975 return this.scrollIncrement || (this.resizeTabs ? this.lastTabWidth+2 : 100);
978 <div id="method-Ext.TabPanel-scrollToTab"></div>/**
979 * Scrolls to a particular tab if tab scrolling is enabled
980 * @param {Panel} item The item to scroll to
981 * @param {Boolean} animate True to enable animations
984 scrollToTab : function(item, animate){
988 var el = this.getTabEl(item),
989 pos = this.getScrollPos(),
990 area = this.getScrollArea(),
991 left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos,
992 right = left + el.offsetWidth;
994 this.scrollTo(left, animate);
995 }else if(right > (pos + area)){
996 this.scrollTo(right - area, animate);
1001 scrollTo : function(pos, animate){
1002 this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
1004 this.updateScrollButtons();
1008 onWheel : function(e){
1009 var d = e.getWheelDelta()*this.wheelIncrement*-1;
1012 var pos = this.getScrollPos(),
1014 sw = this.getScrollWidth()-this.getScrollArea();
1016 var s = Math.max(0, Math.min(sw, newpos));
1018 this.scrollTo(s, false);
1023 onScrollRight : function(){
1024 var sw = this.getScrollWidth()-this.getScrollArea(),
1025 pos = this.getScrollPos(),
1026 s = Math.min(sw, pos + this.getScrollIncrement());
1028 this.scrollTo(s, this.animScroll);
1033 onScrollLeft : function(){
1034 var pos = this.getScrollPos(),
1035 s = Math.max(0, pos - this.getScrollIncrement());
1037 this.scrollTo(s, this.animScroll);
1042 updateScrollButtons : function(){
1043 var pos = this.getScrollPos();
1044 this.scrollLeft[pos === 0 ? 'addClass' : 'removeClass']('x-tab-scroller-left-disabled');
1045 this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('x-tab-scroller-right-disabled');
1049 beforeDestroy : function() {
1050 Ext.destroy(this.leftRepeater, this.rightRepeater);
1051 this.deleteMembers('strip', 'edge', 'scrollLeft', 'scrollRight', 'stripWrap');
1052 this.activeTab = null;
1053 Ext.TabPanel.superclass.beforeDestroy.apply(this);
1056 <div id="cfg-Ext.TabPanel-collapsible"></div>/**
1057 * @cfg {Boolean} collapsible
1060 <div id="cfg-Ext.TabPanel-header"></div>/**
1061 * @cfg {String} header
1064 <div id="cfg-Ext.TabPanel-headerAsText"></div>/**
1065 * @cfg {Boolean} headerAsText
1068 <div id="prop-Ext.TabPanel-header"></div>/**
1072 <div id="cfg-Ext.TabPanel-null"></div>/**
1076 <div id="cfg-Ext.TabPanel-tools"></div>/**
1077 * @cfg {Array} tools
1080 <div id="cfg-Ext.TabPanel-toolTemplate"></div>/**
1081 * @cfg {Array} toolTemplate
1084 <div id="cfg-Ext.TabPanel-hideCollapseTool"></div>/**
1085 * @cfg {Boolean} hideCollapseTool
1088 <div id="cfg-Ext.TabPanel-titleCollapse"></div>/**
1089 * @cfg {Boolean} titleCollapse
1092 <div id="cfg-Ext.TabPanel-collapsed"></div>/**
1093 * @cfg {Boolean} collapsed
1096 <div id="cfg-Ext.TabPanel-layout"></div>/**
1097 * @cfg {String} layout
1100 <div id="cfg-Ext.TabPanel-preventBodyReset"></div>/**
1101 * @cfg {Boolean} preventBodyReset
1105 Ext.reg('tabpanel', Ext.TabPanel);
1107 <div id="method-Ext.TabPanel-activate"></div>/**
1108 * See {@link #setActiveTab}. Sets the specified tab as the active tab. This method fires
1109 * the {@link #beforetabchange} event which can <tt>return false</tt> to cancel the tab change.
1110 * @param {String/Panel} tab The id or tab Panel to activate
1113 Ext.TabPanel.prototype.activate = Ext.TabPanel.prototype.setActiveTab;
1115 // private utility class used by TabPanel
1116 Ext.TabPanel.AccessStack = function(){
1119 add : function(item){
1121 if(items.length > 10){
1126 remove : function(item){
1128 for(var i = 0, len = items.length; i < len; i++) {
1129 if(items[i] != item){