~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/widgets/TabPanel.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.TabPanel
 
11
 * <p>A basic tab container. TabPanels can be used exactly like a standard {@link Ext.Panel}
 
12
 * for layout purposes, but also have special support for containing child Components
 
13
 * (<tt>{@link Ext.Container#items items}</tt>) that are managed using a
 
14
 * {@link Ext.layout.CardLayout CardLayout layout manager}, and displayed as separate tabs.</p>
 
15
 * 
 
16
 * <b>Note:</b> By default, a tab's close tool <i>destroys</i> the child tab Component
 
17
 * and all its descendants. This makes the child tab Component, and all its descendants <b>unusable</b>. To enable
 
18
 * re-use of a tab, configure the TabPanel with <b><code>{@link #autoDestroy autoDestroy: false}</code></b>.
 
19
 * 
 
20
 * <p><b><u>TabPanel header/footer elements</u></b></p> 
 
21
 * <p>TabPanels use their {@link Ext.Panel#header header} or {@link Ext.Panel#footer footer} element
 
22
 * (depending on the {@link #tabPosition} configuration) to accommodate the tab selector buttons.
 
23
 * This means that a TabPanel will not display any configured title, and will not display any
 
24
 * configured header {@link Ext.Panel#tools tools}.</p>
 
25
 * <p>To display a header, embed the TabPanel in a {@link Ext.Panel Panel} which uses
 
26
 * <b><tt>{@link Ext.Container#layout layout:'fit'}</tt></b>.</p>
 
27
 * 
 
28
 * <p><b><u>Tab Events</u></b></p> 
 
29
 * <p>There is no actual tab class &mdash; each tab is simply a {@link Ext.BoxComponent Component}
 
30
 * such as a {@link Ext.Panel Panel}. However, when rendered in a TabPanel, each child Component
 
31
 * can fire additional events that only exist for tabs and are not available from other Components.
 
32
 * These events are:</p>
 
33
 * <div><ul class="mdetail-params">
 
34
 * <li><tt><b>{@link Ext.Panel#activate activate}</b></tt> : Fires when this Component becomes
 
35
 * the active tab.</li>
 
36
 * <li><tt><b>{@link Ext.Panel#deactivate deactivate}</b></tt> : Fires when the Component that
 
37
 * was the active tab becomes deactivated.</li>
 
38
 * </ul></div>
 
39
 * <p><b><u>Creating TabPanels from Code</u></b></p> 
 
40
 * <p>TabPanels can be created and rendered completely in code, as in this example:</p>
 
41
 * <pre><code>
 
42
var tabs = new Ext.TabPanel({
 
43
    renderTo: Ext.getBody(),
 
44
    activeTab: 0,
 
45
    items: [{
 
46
        title: 'Tab 1',
 
47
        html: 'A simple tab'
 
48
    },{
 
49
        title: 'Tab 2',
 
50
        html: 'Another one'
 
51
    }]
 
52
});
 
53
</code></pre>
 
54
 * <p><b><u>Creating TabPanels from Existing Markup</u></b></p> 
 
55
 * <p>TabPanels can also be rendered from pre-existing markup in a couple of ways.</p>
 
56
 * <div><ul class="mdetail-params">
 
57
 * 
 
58
 * <li>Pre-Structured Markup</li>
 
59
 * <div class="sub-desc">
 
60
 * <p>A container div with one or more nested tab divs with class <tt>'x-tab'</tt> can be rendered entirely
 
61
 * from existing markup (See the {@link #autoTabs} example).</p>
 
62
 * </div>
 
63
 * 
 
64
 * <li>Un-Structured Markup</li>
 
65
 * <div class="sub-desc">
 
66
 * <p>A TabPanel can also be rendered from markup that is not strictly structured by simply specifying by id
 
67
 * which elements should be the container and the tabs. Using this method tab content can be pulled from different
 
68
 * elements within the page by id regardless of page structure. For example:</p>
 
69
 * <pre><code>
 
70
var tabs = new Ext.TabPanel({
 
71
    renderTo: 'my-tabs',
 
72
    activeTab: 0,
 
73
    items:[
 
74
        {contentEl:'tab1', title:'Tab 1'},
 
75
        {contentEl:'tab2', title:'Tab 2'}
 
76
    ]
 
77
});
 
78
 
 
79
// Note that the tabs do not have to be nested within the container (although they can be)
 
80
&lt;div id="my-tabs">&lt;/div>
 
81
&lt;div id="tab1" class="x-hide-display">A simple tab&lt;/div>
 
82
&lt;div id="tab2" class="x-hide-display">Another one&lt;/div>
 
83
</code></pre>
 
84
 * Note that the tab divs in this example contain the class <tt>'x-hide-display'</tt> so that they can be rendered
 
85
 * deferred without displaying outside the tabs. You could alternately set <tt>{@link #deferredRender} = false </tt>
 
86
 * to render all content tabs on page load. 
 
87
 * </div>
 
88
 * 
 
89
 * </ul></div>
 
90
 * 
 
91
 * @extends Ext.Panel
 
92
 * @constructor
 
93
 * @param {Object} config The configuration options
 
94
 * @xtype tabpanel
 
95
 */
 
96
Ext.TabPanel = Ext.extend(Ext.Panel,  {
 
97
    /**
 
98
     * @cfg {Boolean} layoutOnTabChange
 
99
     * Set to true to force a layout of the active tab when the tab is changed. Defaults to false.
 
100
     * See {@link Ext.layout.CardLayout}.<code>{@link Ext.layout.CardLayout#layoutOnCardChange layoutOnCardChange}</code>.
 
101
     */
 
102
    /**
 
103
     * @cfg {String} tabCls <b>This config option is used on <u>child Components</u> of ths TabPanel.</b> A CSS
 
104
     * class name applied to the tab strip item representing the child Component, allowing special
 
105
     * styling to be applied.
 
106
     */
 
107
    /**
 
108
     * @cfg {Boolean} monitorResize True to automatically monitor window resize events and rerender the layout on
 
109
     * browser resize (defaults to true).
 
110
     */
 
111
    monitorResize : true,
 
112
    /**
 
113
     * @cfg {Boolean} deferredRender
 
114
     * <p><tt>true</tt> by default to defer the rendering of child <tt>{@link Ext.Container#items items}</tt>
 
115
     * to the browsers DOM until a tab is activated. <tt>false</tt> will render all contained
 
116
     * <tt>{@link Ext.Container#items items}</tt> as soon as the {@link Ext.layout.CardLayout layout}
 
117
     * is rendered. If there is a significant amount of content or a lot of heavy controls being
 
118
     * rendered into panels that are not displayed by default, setting this to <tt>true</tt> might
 
119
     * improve performance.</p>
 
120
     * <br><p>The <tt>deferredRender</tt> property is internally passed to the layout manager for
 
121
     * TabPanels ({@link Ext.layout.CardLayout}) as its {@link Ext.layout.CardLayout#deferredRender}
 
122
     * configuration value.</p>
 
123
     * <br><p><b>Note</b>: leaving <tt>deferredRender</tt> as <tt>true</tt> means that the content
 
124
     * within an unactivated tab will not be available. For example, this means that if the TabPanel
 
125
     * is within a {@link Ext.form.FormPanel form}, then until a tab is activated, any Fields within
 
126
     * unactivated tabs will not be rendered, and will therefore not be submitted and will not be
 
127
     * available to either {@link Ext.form.BasicForm#getValues getValues} or
 
128
     * {@link Ext.form.BasicForm#setValues setValues}.</p>    
 
129
     */
 
130
    deferredRender : true,
 
131
    /**
 
132
     * @cfg {Number} tabWidth The initial width in pixels of each new tab (defaults to 120).
 
133
     */
 
134
    tabWidth : 120,
 
135
    /**
 
136
     * @cfg {Number} minTabWidth The minimum width in pixels for each tab when {@link #resizeTabs} = true (defaults to 30).
 
137
     */
 
138
    minTabWidth : 30,
 
139
    /**
 
140
     * @cfg {Boolean} resizeTabs True to automatically resize each tab so that the tabs will completely fill the
 
141
     * tab strip (defaults to false).  Setting this to true may cause specific widths that might be set per tab to
 
142
     * be overridden in order to fit them all into view (although {@link #minTabWidth} will always be honored).
 
143
     */
 
144
    resizeTabs : false,
 
145
    /**
 
146
     * @cfg {Boolean} enableTabScroll True to enable scrolling to tabs that may be invisible due to overflowing the
 
147
     * overall TabPanel width. Only available with tabPosition:'top' (defaults to false).
 
148
     */
 
149
    enableTabScroll : false,
 
150
    /**
 
151
     * @cfg {Number} scrollIncrement The number of pixels to scroll each time a tab scroll button is pressed
 
152
     * (defaults to <tt>100</tt>, or if <tt>{@link #resizeTabs} = true</tt>, the calculated tab width).  Only
 
153
     * applies when <tt>{@link #enableTabScroll} = true</tt>.
 
154
     */
 
155
    scrollIncrement : 0,
 
156
    /**
 
157
     * @cfg {Number} scrollRepeatInterval Number of milliseconds between each scroll while a tab scroll button is
 
158
     * continuously pressed (defaults to <tt>400</tt>).
 
159
     */
 
160
    scrollRepeatInterval : 400,
 
161
    /**
 
162
     * @cfg {Float} scrollDuration The number of milliseconds that each scroll animation should last (defaults
 
163
     * to <tt>.35</tt>). Only applies when <tt>{@link #animScroll} = true</tt>.
 
164
     */
 
165
    scrollDuration : .35,
 
166
    /**
 
167
     * @cfg {Boolean} animScroll True to animate tab scrolling so that hidden tabs slide smoothly into view (defaults
 
168
     * to <tt>true</tt>).  Only applies when <tt>{@link #enableTabScroll} = true</tt>.
 
169
     */
 
170
    animScroll : true,
 
171
    /**
 
172
     * @cfg {String} tabPosition The position where the tab strip should be rendered (defaults to <tt>'top'</tt>).
 
173
     * The only other supported value is <tt>'bottom'</tt>.  <b>Note</b>: tab scrolling is only supported for
 
174
     * <tt>tabPosition: 'top'</tt>.
 
175
     */
 
176
    tabPosition : 'top',
 
177
    /**
 
178
     * @cfg {String} baseCls The base CSS class applied to the panel (defaults to <tt>'x-tab-panel'</tt>).
 
179
     */
 
180
    baseCls : 'x-tab-panel',
 
181
    /**
 
182
     * @cfg {Boolean} autoTabs
 
183
     * <p><tt>true</tt> to query the DOM for any divs with a class of 'x-tab' to be automatically converted
 
184
     * to tabs and added to this panel (defaults to <tt>false</tt>).  Note that the query will be executed within
 
185
     * the scope of the container element only (so that multiple tab panels from markup can be supported via this
 
186
     * method).</p>
 
187
     * <p>This method is only possible when the markup is structured correctly as a container with nested divs
 
188
     * containing the class <tt>'x-tab'</tt>. To create TabPanels without these limitations, or to pull tab content
 
189
     * from other elements on the page, see the example at the top of the class for generating tabs from markup.</p>
 
190
     * <p>There are a couple of things to note when using this method:<ul>
 
191
     * <li>When using the <tt>autoTabs</tt> config (as opposed to passing individual tab configs in the TabPanel's
 
192
     * {@link #items} collection), you must use <tt>{@link #applyTo}</tt> to correctly use the specified <tt>id</tt>
 
193
     * as the tab container. The <tt>autoTabs</tt> method <em>replaces</em> existing content with the TabPanel
 
194
     * components.</li>
 
195
     * <li>Make sure that you set <tt>{@link #deferredRender}: false</tt> so that the content elements for each
 
196
     * tab will be rendered into the TabPanel immediately upon page load, otherwise they will not be transformed
 
197
     * until each tab is activated and will be visible outside the TabPanel.</li>
 
198
     * </ul>Example usage:</p>
 
199
     * <pre><code>
 
200
var tabs = new Ext.TabPanel({
 
201
    applyTo: 'my-tabs',
 
202
    activeTab: 0,
 
203
    deferredRender: false,
 
204
    autoTabs: true
 
205
});
 
206
 
 
207
// This markup will be converted to a TabPanel from the code above
 
208
&lt;div id="my-tabs">
 
209
    &lt;div class="x-tab" title="Tab 1">A simple tab&lt;/div>
 
210
    &lt;div class="x-tab" title="Tab 2">Another one&lt;/div>
 
211
&lt;/div>
 
212
</code></pre>
 
213
     */
 
214
    autoTabs : false,
 
215
    /**
 
216
     * @cfg {String} autoTabSelector The CSS selector used to search for tabs in existing markup when
 
217
     * <tt>{@link #autoTabs} = true</tt> (defaults to <tt>'div.x-tab'</tt>).  This can be any valid selector
 
218
     * supported by {@link Ext.DomQuery#select}. Note that the query will be executed within the scope of this
 
219
     * tab panel only (so that multiple tab panels from markup can be supported on a page).
 
220
     */
 
221
    autoTabSelector : 'div.x-tab',
 
222
    /**
 
223
     * @cfg {String/Number} activeTab A string id or the numeric index of the tab that should be initially
 
224
     * activated on render (defaults to none).
 
225
     */
 
226
    activeTab : null,
 
227
    /**
 
228
     * @cfg {Number} tabMargin The number of pixels of space to calculate into the sizing and scrolling of
 
229
     * tabs. If you change the margin in CSS, you will need to update this value so calculations are correct
 
230
     * with either <tt>{@link #resizeTabs}</tt> or scrolling tabs. (defaults to <tt>2</tt>)
 
231
     */
 
232
    tabMargin : 2,
 
233
    /**
 
234
     * @cfg {Boolean} plain </tt>true</tt> to render the tab strip without a background container image
 
235
     * (defaults to <tt>false</tt>).
 
236
     */
 
237
    plain : false,
 
238
    /**
 
239
     * @cfg {Number} wheelIncrement For scrolling tabs, the number of pixels to increment on mouse wheel
 
240
     * scrolling (defaults to <tt>20</tt>).
 
241
     */
 
242
    wheelIncrement : 20,
 
243
 
 
244
    /*
 
245
     * This is a protected property used when concatenating tab ids to the TabPanel id for internal uniqueness.
 
246
     * It does not generally need to be changed, but can be if external code also uses an id scheme that can
 
247
     * potentially clash with this one.
 
248
     */
 
249
    idDelimiter : '__',
 
250
 
 
251
    // private
 
252
    itemCls : 'x-tab-item',
 
253
 
 
254
    // private config overrides
 
255
    elements : 'body',
 
256
    headerAsText : false,
 
257
    frame : false,
 
258
    hideBorders :true,
 
259
 
 
260
    // private
 
261
    initComponent : function(){
 
262
        this.frame = false;
 
263
        Ext.TabPanel.superclass.initComponent.call(this);
 
264
        this.addEvents(
 
265
            /**
 
266
             * @event beforetabchange
 
267
             * Fires before the active tab changes. Handlers can <tt>return false</tt> to cancel the tab change.
 
268
             * @param {TabPanel} this
 
269
             * @param {Panel} newTab The tab being activated
 
270
             * @param {Panel} currentTab The current active tab
 
271
             */
 
272
            'beforetabchange',
 
273
            /**
 
274
             * @event tabchange
 
275
             * Fires after the active tab has changed.
 
276
             * @param {TabPanel} this
 
277
             * @param {Panel} tab The new active tab
 
278
             */
 
279
            'tabchange',
 
280
            /**
 
281
             * @event contextmenu
 
282
             * Relays the contextmenu event from a tab selector element in the tab strip.
 
283
             * @param {TabPanel} this
 
284
             * @param {Panel} tab The target tab
 
285
             * @param {EventObject} e
 
286
             */
 
287
            'contextmenu'
 
288
        );
 
289
        /**
 
290
         * @cfg {Object} layoutConfig
 
291
         * TabPanel implicitly uses {@link Ext.layout.CardLayout} as its layout manager.
 
292
         * <code>layoutConfig</code> may be used to configure this layout manager.
 
293
         * <code>{@link #deferredRender}</code> and <code>{@link #layoutOnTabChange}</code>
 
294
         * configured on the TabPanel will be applied as configs to the layout manager.
 
295
         */
 
296
        this.setLayout(new Ext.layout.CardLayout(Ext.apply({
 
297
            layoutOnCardChange: this.layoutOnTabChange,
 
298
            deferredRender: this.deferredRender
 
299
        }, this.layoutConfig)));
 
300
 
 
301
        if(this.tabPosition == 'top'){
 
302
            this.elements += ',header';
 
303
            this.stripTarget = 'header';
 
304
        }else {
 
305
            this.elements += ',footer';
 
306
            this.stripTarget = 'footer';
 
307
        }
 
308
        if(!this.stack){
 
309
            this.stack = Ext.TabPanel.AccessStack();
 
310
        }
 
311
        this.initItems();
 
312
    },
 
313
 
 
314
    // private
 
315
    onRender : function(ct, position){
 
316
        Ext.TabPanel.superclass.onRender.call(this, ct, position);
 
317
 
 
318
        if(this.plain){
 
319
            var pos = this.tabPosition == 'top' ? 'header' : 'footer';
 
320
            this[pos].addClass('x-tab-panel-'+pos+'-plain');
 
321
        }
 
322
 
 
323
        var st = this[this.stripTarget];
 
324
 
 
325
        this.stripWrap = st.createChild({cls:'x-tab-strip-wrap', cn:{
 
326
            tag:'ul', cls:'x-tab-strip x-tab-strip-'+this.tabPosition}});
 
327
 
 
328
        var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
 
329
        this.stripSpacer = st.createChild({cls:'x-tab-strip-spacer'}, beforeEl);
 
330
        this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
 
331
 
 
332
        this.edge = this.strip.createChild({tag:'li', cls:'x-tab-edge'});
 
333
        this.strip.createChild({cls:'x-clear'});
 
334
 
 
335
        this.body.addClass('x-tab-panel-body-'+this.tabPosition);
 
336
 
 
337
        /**
 
338
         * @cfg {Template/XTemplate} itemTpl <p>(Optional) A {@link Ext.Template Template} or
 
339
         * {@link Ext.XTemplate XTemplate} which may be provided to process the data object returned from
 
340
         * <tt>{@link #getTemplateArgs}</tt> to produce a clickable selector element in the tab strip.</p>
 
341
         * <p>The main element created should be a <tt>&lt;li></tt> element. In order for a click event on
 
342
         * a selector element to be connected to its item, it must take its <i>id</i> from the TabPanel's
 
343
         * native <tt>{@link #getTemplateArgs}</tt>.</p>
 
344
         * <p>The child element which contains the title text must be marked by the CSS class
 
345
         * <tt>x-tab-strip-inner</tt>.</p>
 
346
         * <p>To enable closability, the created element should contain an element marked by the CSS class
 
347
         * <tt>x-tab-strip-close</tt>.</p>
 
348
         * <p>If a custom <tt>itemTpl</tt> is supplied, it is the developer's responsibility to create CSS
 
349
         * style rules to create the desired appearance.</p>
 
350
         * Below is an example of how to create customized tab selector items:<code><pre>
 
351
new Ext.TabPanel({
 
352
    renderTo: document.body,
 
353
    minTabWidth: 115,
 
354
    tabWidth: 135,
 
355
    enableTabScroll: true,
 
356
    width: 600,
 
357
    height: 250,
 
358
    defaults: {autoScroll:true},
 
359
    itemTpl: new Ext.XTemplate(
 
360
    '&lt;li class="{cls}" id="{id}" style="overflow:hidden">',
 
361
         '&lt;tpl if="closable">',
 
362
            '&lt;a class="x-tab-strip-close" onclick="return false;">&lt;/a>',
 
363
         '&lt;/tpl>',
 
364
         '&lt;a class="x-tab-right" href="#" onclick="return false;" style="padding-left:6px">',
 
365
            '&lt;em class="x-tab-left">',
 
366
                '&lt;span class="x-tab-strip-inner">',
 
367
                    '&lt;img src="{src}" style="float:left;margin:3px 3px 0 0">',
 
368
                    '&lt;span style="margin-left:20px" class="x-tab-strip-text {iconCls}">{text} {extra}&lt;/span>',
 
369
                '&lt;/span>',
 
370
            '&lt;/em>',
 
371
        '&lt;/a>',
 
372
    '&lt;/li>'
 
373
    ),
 
374
    getTemplateArgs: function(item) {
 
375
//      Call the native method to collect the base data. Like the ID!
 
376
        var result = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
 
377
 
 
378
//      Add stuff used in our template
 
379
        return Ext.apply(result, {
 
380
            closable: item.closable,
 
381
            src: item.iconSrc,
 
382
            extra: item.extraText || ''
 
383
        });
 
384
    },
 
385
    items: [{
 
386
        title: 'New Tab 1',
 
387
        iconSrc: '../shared/icons/fam/grid.png',
 
388
        html: 'Tab Body 1',
 
389
        closable: true
 
390
    }, {
 
391
        title: 'New Tab 2',
 
392
        iconSrc: '../shared/icons/fam/grid.png',
 
393
        html: 'Tab Body 2',
 
394
        extraText: 'Extra stuff in the tab button'
 
395
    }]
 
396
});
 
397
</pre></code>
 
398
         */
 
399
        if(!this.itemTpl){
 
400
            var tt = new Ext.Template(
 
401
                 '<li class="{cls}" id="{id}"><a class="x-tab-strip-close" onclick="return false;"></a>',
 
402
                 '<a class="x-tab-right" href="#" onclick="return false;"><em class="x-tab-left">',
 
403
                 '<span class="x-tab-strip-inner"><span class="x-tab-strip-text {iconCls}">{text}</span></span>',
 
404
                 '</em></a></li>'
 
405
            );
 
406
            tt.disableFormats = true;
 
407
            tt.compile();
 
408
            Ext.TabPanel.prototype.itemTpl = tt;
 
409
        }
 
410
 
 
411
        this.items.each(this.initTab, this);
 
412
    },
 
413
 
 
414
    // private
 
415
    afterRender : function(){
 
416
        Ext.TabPanel.superclass.afterRender.call(this);
 
417
        if(this.autoTabs){
 
418
            this.readTabs(false);
 
419
        }
 
420
        if(this.activeTab !== undefined){
 
421
            var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
 
422
            delete this.activeTab;
 
423
            this.setActiveTab(item);
 
424
        }
 
425
    },
 
426
 
 
427
    // private
 
428
    initEvents : function(){
 
429
        Ext.TabPanel.superclass.initEvents.call(this);
 
430
        this.on('add', this.onAdd, this, {target: this});
 
431
        this.on('remove', this.onRemove, this, {target: this});
 
432
 
 
433
        this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
 
434
        this.mon(this.strip, 'contextmenu', this.onStripContextMenu, this);
 
435
        if(this.enableTabScroll){
 
436
            this.mon(this.strip, 'mousewheel', this.onWheel, this);
 
437
        }
 
438
    },
 
439
 
 
440
    // private
 
441
    findTargets : function(e){
 
442
        var item = null;
 
443
        var itemEl = e.getTarget('li', this.strip);
 
444
        if(itemEl){
 
445
            item = this.getComponent(itemEl.id.split(this.idDelimiter)[1]);
 
446
            if(item.disabled){
 
447
                return {
 
448
                    close : null,
 
449
                    item : null,
 
450
                    el : null
 
451
                };
 
452
            }
 
453
        }
 
454
        return {
 
455
            close : e.getTarget('.x-tab-strip-close', this.strip),
 
456
            item : item,
 
457
            el : itemEl
 
458
        };
 
459
    },
 
460
 
 
461
    // private
 
462
    onStripMouseDown : function(e){
 
463
        if(e.button != 0){
 
464
            return;
 
465
        }
 
466
        e.preventDefault();
 
467
        var t = this.findTargets(e);
 
468
        if(t.close){
 
469
            if (t.item.fireEvent('beforeclose', t.item) !== false) {
 
470
                t.item.fireEvent('close', t.item);
 
471
                this.remove(t.item);                
 
472
            }
 
473
            return;
 
474
        }
 
475
        if(t.item && t.item != this.activeTab){
 
476
            this.setActiveTab(t.item);
 
477
        }
 
478
    },
 
479
 
 
480
    // private
 
481
    onStripContextMenu : function(e){
 
482
        e.preventDefault();
 
483
        var t = this.findTargets(e);
 
484
        if(t.item){
 
485
            this.fireEvent('contextmenu', this, t.item, e);
 
486
        }
 
487
    },
 
488
 
 
489
    /**
 
490
     * True to scan the markup in this tab panel for <tt>{@link #autoTabs}</tt> using the
 
491
     * <tt>{@link #autoTabSelector}</tt>
 
492
     * @param {Boolean} removeExisting True to remove existing tabs
 
493
     */
 
494
    readTabs : function(removeExisting){
 
495
        if(removeExisting === true){
 
496
            this.items.each(function(item){
 
497
                this.remove(item);
 
498
            }, this);
 
499
        }
 
500
        var tabs = this.el.query(this.autoTabSelector);
 
501
        for(var i = 0, len = tabs.length; i < len; i++){
 
502
            var tab = tabs[i];
 
503
            var title = tab.getAttribute('title');
 
504
            tab.removeAttribute('title');
 
505
            this.add({
 
506
                title: title,
 
507
                contentEl: tab
 
508
            });
 
509
        }
 
510
    },
 
511
 
 
512
    // private
 
513
    initTab : function(item, index){
 
514
        var before = this.strip.dom.childNodes[index];
 
515
        var p = this.getTemplateArgs(item);
 
516
        var el = before ?
 
517
                 this.itemTpl.insertBefore(before, p) :
 
518
                 this.itemTpl.append(this.strip, p);
 
519
 
 
520
        Ext.fly(el).addClassOnOver('x-tab-strip-over');
 
521
 
 
522
        if(item.tabTip){
 
523
            Ext.fly(el).child('span.x-tab-strip-text', true).qtip = item.tabTip;
 
524
        }
 
525
        item.tabEl = el;
 
526
 
 
527
        item.on('disable', this.onItemDisabled, this);
 
528
        item.on('enable', this.onItemEnabled, this);
 
529
        item.on('titlechange', this.onItemTitleChanged, this);
 
530
        item.on('iconchange', this.onItemIconChanged, this);
 
531
        item.on('beforeshow', this.onBeforeShowItem, this);
 
532
    },
 
533
 
 
534
    /**
 
535
     * <p>Provides template arguments for rendering a tab selector item in the tab strip.</p>
 
536
     * <p>This method returns an object hash containing properties used by the TabPanel's <tt>{@link #itemTpl}</tt>
 
537
     * to create a formatted, clickable tab selector element. The properties which must be returned
 
538
     * are:</p><div class="mdetail-params"><ul>
 
539
     * <li><b>id</b> : String<div class="sub-desc">A unique identifier which links to the item</div></li>
 
540
     * <li><b>text</b> : String<div class="sub-desc">The text to display</div></li>
 
541
     * <li><b>cls</b> : String<div class="sub-desc">The CSS class name</div></li>
 
542
     * <li><b>iconCls</b> : String<div class="sub-desc">A CSS class to provide appearance for an icon.</div></li>
 
543
     * </ul></div>
 
544
     * @param {BoxComponent} item The {@link Ext.BoxComponent BoxComponent} for which to create a selector element in the tab strip.
 
545
     * @return {Object} An object hash containing the properties required to render the selector element.
 
546
     */
 
547
    getTemplateArgs : function(item) {
 
548
        var cls = item.closable ? 'x-tab-strip-closable' : '';
 
549
        if(item.disabled){
 
550
            cls += ' x-item-disabled';
 
551
        }
 
552
        if(item.iconCls){
 
553
            cls += ' x-tab-with-icon';
 
554
        }
 
555
        if(item.tabCls){
 
556
            cls += ' ' + item.tabCls;
 
557
        }
 
558
        
 
559
        return {
 
560
            id: this.id + this.idDelimiter + item.getItemId(),
 
561
            text: item.title,
 
562
            cls: cls,
 
563
            iconCls: item.iconCls || ''
 
564
        };
 
565
    },
 
566
    
 
567
    // private
 
568
    onAdd : function(tp, item, index){
 
569
        this.initTab(item, index);
 
570
        if(this.items.getCount() == 1){
 
571
            this.syncSize();
 
572
        }
 
573
        this.delegateUpdates();
 
574
    },
 
575
 
 
576
    // private
 
577
    onBeforeAdd : function(item){
 
578
        var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
 
579
        if(existing){
 
580
            this.setActiveTab(item);
 
581
            return false;
 
582
        }
 
583
        Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
 
584
        var es = item.elements;
 
585
        item.elements = es ? es.replace(',header', '') : es;
 
586
        item.border = (item.border === true);
 
587
    },
 
588
 
 
589
    // private
 
590
    onRemove : function(tp, item){
 
591
        Ext.destroy(Ext.get(this.getTabEl(item)));
 
592
        this.stack.remove(item);
 
593
        item.un('disable', this.onItemDisabled, this);
 
594
        item.un('enable', this.onItemEnabled, this);
 
595
        item.un('titlechange', this.onItemTitleChanged, this);
 
596
        item.un('iconchange', this.onItemIconChanged, this);
 
597
        item.un('beforeshow', this.onBeforeShowItem, this);
 
598
        if(item == this.activeTab){
 
599
            var next = this.stack.next();
 
600
            if(next){
 
601
                this.setActiveTab(next);
 
602
            }else if(this.items.getCount() > 0){
 
603
                this.setActiveTab(0);
 
604
            }else{
 
605
                this.activeTab = null;
 
606
            }
 
607
        }
 
608
        this.delegateUpdates();
 
609
    },
 
610
 
 
611
    // private
 
612
    onBeforeShowItem : function(item){
 
613
        if(item != this.activeTab){
 
614
            this.setActiveTab(item);
 
615
            return false;
 
616
        }
 
617
    },
 
618
 
 
619
    // private
 
620
    onItemDisabled : function(item){
 
621
        var el = this.getTabEl(item);
 
622
        if(el){
 
623
            Ext.fly(el).addClass('x-item-disabled');
 
624
        }
 
625
        this.stack.remove(item);
 
626
    },
 
627
 
 
628
    // private
 
629
    onItemEnabled : function(item){
 
630
        var el = this.getTabEl(item);
 
631
        if(el){
 
632
            Ext.fly(el).removeClass('x-item-disabled');
 
633
        }
 
634
    },
 
635
 
 
636
    // private
 
637
    onItemTitleChanged : function(item){
 
638
        var el = this.getTabEl(item);
 
639
        if(el){
 
640
            Ext.fly(el).child('span.x-tab-strip-text', true).innerHTML = item.title;
 
641
        }
 
642
    },
 
643
    
 
644
    //private
 
645
    onItemIconChanged : function(item, iconCls, oldCls){
 
646
        var el = this.getTabEl(item);
 
647
        if(el){
 
648
            Ext.fly(el).child('span.x-tab-strip-text').replaceClass(oldCls, iconCls);
 
649
        }
 
650
    },
 
651
 
 
652
    /**
 
653
     * Gets the DOM element for the tab strip item which activates the child panel with the specified
 
654
     * ID. Access this to change the visual treatment of the item, for example by changing the CSS class name.
 
655
     * @param {Panel/Number/String} tab The tab component, or the tab's index, or the tabs id or itemId.
 
656
     * @return {HTMLElement} The DOM node
 
657
     */
 
658
    getTabEl : function(item){
 
659
        var itemId = (Ext.isObject(item) ? item : this.getComponent(item)).getItemId();
 
660
        return document.getElementById(this.id+this.idDelimiter+itemId);
 
661
    },
 
662
 
 
663
    // private
 
664
    onResize : function(){
 
665
        Ext.TabPanel.superclass.onResize.apply(this, arguments);
 
666
        this.delegateUpdates();
 
667
    },
 
668
 
 
669
    /**
 
670
     * Suspends any internal calculations or scrolling while doing a bulk operation. See {@link #endUpdate}
 
671
     */
 
672
    beginUpdate : function(){
 
673
        this.suspendUpdates = true;
 
674
    },
 
675
 
 
676
    /**
 
677
     * Resumes calculations and scrolling at the end of a bulk operation. See {@link #beginUpdate}
 
678
     */
 
679
    endUpdate : function(){
 
680
        this.suspendUpdates = false;
 
681
        this.delegateUpdates();
 
682
    },
 
683
 
 
684
    /**
 
685
     * Hides the tab strip item for the passed tab
 
686
     * @param {Number/String/Panel} item The tab index, id or item
 
687
     */
 
688
    hideTabStripItem : function(item){
 
689
        item = this.getComponent(item);
 
690
        var el = this.getTabEl(item);
 
691
        if(el){
 
692
            el.style.display = 'none';
 
693
            this.delegateUpdates();
 
694
        }
 
695
        this.stack.remove(item);
 
696
    },
 
697
 
 
698
    /**
 
699
     * Unhides the tab strip item for the passed tab
 
700
     * @param {Number/String/Panel} item The tab index, id or item
 
701
     */
 
702
    unhideTabStripItem : function(item){
 
703
        item = this.getComponent(item);
 
704
        var el = this.getTabEl(item);
 
705
        if(el){
 
706
            el.style.display = '';
 
707
            this.delegateUpdates();
 
708
        }
 
709
    },
 
710
 
 
711
    // private
 
712
    delegateUpdates : function(){
 
713
        if(this.suspendUpdates){
 
714
            return;
 
715
        }
 
716
        if(this.resizeTabs && this.rendered){
 
717
            this.autoSizeTabs();
 
718
        }
 
719
        if(this.enableTabScroll && this.rendered){
 
720
            this.autoScrollTabs();
 
721
        }
 
722
    },
 
723
 
 
724
    // private
 
725
    autoSizeTabs : function(){
 
726
        var count = this.items.length;
 
727
        var ce = this.tabPosition != 'bottom' ? 'header' : 'footer';
 
728
        var ow = this[ce].dom.offsetWidth;
 
729
        var aw = this[ce].dom.clientWidth;
 
730
 
 
731
        if(!this.resizeTabs || count < 1 || !aw){ // !aw for display:none
 
732
            return;
 
733
        }
 
734
 
 
735
        var each = Math.max(Math.min(Math.floor((aw-4) / count) - this.tabMargin, this.tabWidth), this.minTabWidth); // -4 for float errors in IE
 
736
        this.lastTabWidth = each;
 
737
        var lis = this.strip.query("li:not([className^=x-tab-edge])");
 
738
        for(var i = 0, len = lis.length; i < len; i++) {
 
739
            var li = lis[i];
 
740
            var inner = Ext.fly(li).child('.x-tab-strip-inner', true);
 
741
            var tw = li.offsetWidth;
 
742
            var iw = inner.offsetWidth;
 
743
            inner.style.width = (each - (tw-iw)) + 'px';
 
744
        }
 
745
    },
 
746
 
 
747
    // private
 
748
    adjustBodyWidth : function(w){
 
749
        if(this.header){
 
750
            this.header.setWidth(w);
 
751
        }
 
752
        if(this.footer){
 
753
            this.footer.setWidth(w);
 
754
        }
 
755
        return w;
 
756
    },
 
757
 
 
758
    /**
 
759
     * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
 
760
     * can <tt>return false</tt> to cancel the tab change.
 
761
     * @param {String/Panel} tab The id or tab Panel to activate
 
762
     */
 
763
    setActiveTab : function(item){
 
764
        item = this.getComponent(item);
 
765
        if(!item || this.fireEvent('beforetabchange', this, item, this.activeTab) === false){
 
766
            return;
 
767
        }
 
768
        if(!this.rendered){
 
769
            this.activeTab = item;
 
770
            return;
 
771
        }
 
772
        if(this.activeTab != item){
 
773
            if(this.activeTab){
 
774
                var oldEl = this.getTabEl(this.activeTab);
 
775
                if(oldEl){
 
776
                    Ext.fly(oldEl).removeClass('x-tab-strip-active');
 
777
                }
 
778
                this.activeTab.fireEvent('deactivate', this.activeTab);
 
779
            }
 
780
            var el = this.getTabEl(item);
 
781
            Ext.fly(el).addClass('x-tab-strip-active');
 
782
            this.activeTab = item;
 
783
            this.stack.add(item);
 
784
 
 
785
            this.layout.setActiveItem(item);
 
786
            if(this.scrolling){
 
787
                this.scrollToTab(item, this.animScroll);
 
788
            }
 
789
 
 
790
            item.fireEvent('activate', item);
 
791
            this.fireEvent('tabchange', this, item);
 
792
        }
 
793
    },
 
794
 
 
795
    /**
 
796
     * Gets the currently active tab.
 
797
     * @return {Panel} The active tab
 
798
     */
 
799
    getActiveTab : function(){
 
800
        return this.activeTab || null;
 
801
    },
 
802
 
 
803
    /**
 
804
     * Gets the specified tab by id.
 
805
     * @param {String} id The tab id
 
806
     * @return {Panel} The tab
 
807
     */
 
808
    getItem : function(item){
 
809
        return this.getComponent(item);
 
810
    },
 
811
 
 
812
    // private
 
813
    autoScrollTabs : function(){
 
814
        this.pos = this.tabPosition=='bottom' ? this.footer : this.header;
 
815
        var count = this.items.length;
 
816
        var ow = this.pos.dom.offsetWidth;
 
817
        var tw = this.pos.dom.clientWidth;
 
818
 
 
819
        var wrap = this.stripWrap;
 
820
        var wd = wrap.dom;
 
821
        var cw = wd.offsetWidth;
 
822
        var pos = this.getScrollPos();
 
823
        var l = this.edge.getOffsetsTo(this.stripWrap)[0] + pos;
 
824
 
 
825
        if(!this.enableTabScroll || count < 1 || cw < 20){ // 20 to prevent display:none issues
 
826
            return;
 
827
        }
 
828
        if(l <= tw){
 
829
            wd.scrollLeft = 0;
 
830
            wrap.setWidth(tw);
 
831
            if(this.scrolling){
 
832
                this.scrolling = false;
 
833
                this.pos.removeClass('x-tab-scrolling');
 
834
                this.scrollLeft.hide();
 
835
                this.scrollRight.hide();
 
836
                // See here: http://extjs.com/forum/showthread.php?t=49308&highlight=isSafari
 
837
                if(Ext.isAir || Ext.isWebKit){
 
838
                    wd.style.marginLeft = '';
 
839
                    wd.style.marginRight = '';
 
840
                }
 
841
            }
 
842
        }else{
 
843
            if(!this.scrolling){
 
844
                this.pos.addClass('x-tab-scrolling');
 
845
                // See here: http://extjs.com/forum/showthread.php?t=49308&highlight=isSafari
 
846
                if(Ext.isAir || Ext.isWebKit){
 
847
                    wd.style.marginLeft = '18px';
 
848
                    wd.style.marginRight = '18px';
 
849
                }
 
850
            }
 
851
            tw -= wrap.getMargins('lr');
 
852
            wrap.setWidth(tw > 20 ? tw : 20);
 
853
            if(!this.scrolling){
 
854
                if(!this.scrollLeft){
 
855
                    this.createScrollers();
 
856
                }else{
 
857
                    this.scrollLeft.show();
 
858
                    this.scrollRight.show();
 
859
                }
 
860
            }
 
861
            this.scrolling = true;
 
862
            if(pos > (l-tw)){ // ensure it stays within bounds
 
863
                wd.scrollLeft = l-tw;
 
864
            }else{ // otherwise, make sure the active tab is still visible
 
865
                this.scrollToTab(this.activeTab, false);
 
866
            }
 
867
            this.updateScrollButtons();
 
868
        }
 
869
    },
 
870
 
 
871
    // private
 
872
    createScrollers : function(){
 
873
        this.pos.addClass('x-tab-scrolling-' + this.tabPosition);
 
874
        var h = this.stripWrap.dom.offsetHeight;
 
875
 
 
876
        // left
 
877
        var sl = this.pos.insertFirst({
 
878
            cls:'x-tab-scroller-left'
 
879
        });
 
880
        sl.setHeight(h);
 
881
        sl.addClassOnOver('x-tab-scroller-left-over');
 
882
        this.leftRepeater = new Ext.util.ClickRepeater(sl, {
 
883
            interval : this.scrollRepeatInterval,
 
884
            handler: this.onScrollLeft,
 
885
            scope: this
 
886
        });
 
887
        this.scrollLeft = sl;
 
888
 
 
889
        // right
 
890
        var sr = this.pos.insertFirst({
 
891
            cls:'x-tab-scroller-right'
 
892
        });
 
893
        sr.setHeight(h);
 
894
        sr.addClassOnOver('x-tab-scroller-right-over');
 
895
        this.rightRepeater = new Ext.util.ClickRepeater(sr, {
 
896
            interval : this.scrollRepeatInterval,
 
897
            handler: this.onScrollRight,
 
898
            scope: this
 
899
        });
 
900
        this.scrollRight = sr;
 
901
    },
 
902
 
 
903
    // private
 
904
    getScrollWidth : function(){
 
905
        return this.edge.getOffsetsTo(this.stripWrap)[0] + this.getScrollPos();
 
906
    },
 
907
 
 
908
    // private
 
909
    getScrollPos : function(){
 
910
        return parseInt(this.stripWrap.dom.scrollLeft, 10) || 0;
 
911
    },
 
912
 
 
913
    // private
 
914
    getScrollArea : function(){
 
915
        return parseInt(this.stripWrap.dom.clientWidth, 10) || 0;
 
916
    },
 
917
 
 
918
    // private
 
919
    getScrollAnim : function(){
 
920
        return {duration:this.scrollDuration, callback: this.updateScrollButtons, scope: this};
 
921
    },
 
922
 
 
923
    // private
 
924
    getScrollIncrement : function(){
 
925
        return this.scrollIncrement || (this.resizeTabs ? this.lastTabWidth+2 : 100);
 
926
    },
 
927
 
 
928
    /**
 
929
     * Scrolls to a particular tab if tab scrolling is enabled
 
930
     * @param {Panel} item The item to scroll to
 
931
     * @param {Boolean} animate True to enable animations
 
932
     */
 
933
 
 
934
    scrollToTab : function(item, animate){
 
935
        if(!item){ return; }
 
936
        var el = this.getTabEl(item);
 
937
        var pos = this.getScrollPos(), area = this.getScrollArea();
 
938
        var left = Ext.fly(el).getOffsetsTo(this.stripWrap)[0] + pos;
 
939
        var right = left + el.offsetWidth;
 
940
        if(left < pos){
 
941
            this.scrollTo(left, animate);
 
942
        }else if(right > (pos + area)){
 
943
            this.scrollTo(right - area, animate);
 
944
        }
 
945
    },
 
946
 
 
947
    // private
 
948
    scrollTo : function(pos, animate){
 
949
        this.stripWrap.scrollTo('left', pos, animate ? this.getScrollAnim() : false);
 
950
        if(!animate){
 
951
            this.updateScrollButtons();
 
952
        }
 
953
    },
 
954
 
 
955
    onWheel : function(e){
 
956
        var d = e.getWheelDelta()*this.wheelIncrement*-1;
 
957
        e.stopEvent();
 
958
 
 
959
        var pos = this.getScrollPos();
 
960
        var newpos = pos + d;
 
961
        var sw = this.getScrollWidth()-this.getScrollArea();
 
962
 
 
963
        var s = Math.max(0, Math.min(sw, newpos));
 
964
        if(s != pos){
 
965
            this.scrollTo(s, false);
 
966
        }
 
967
    },
 
968
 
 
969
    // private
 
970
    onScrollRight : function(){
 
971
        var sw = this.getScrollWidth()-this.getScrollArea();
 
972
        var pos = this.getScrollPos();
 
973
        var s = Math.min(sw, pos + this.getScrollIncrement());
 
974
        if(s != pos){
 
975
            this.scrollTo(s, this.animScroll);
 
976
        }
 
977
    },
 
978
 
 
979
    // private
 
980
    onScrollLeft : function(){
 
981
        var pos = this.getScrollPos();
 
982
        var s = Math.max(0, pos - this.getScrollIncrement());
 
983
        if(s != pos){
 
984
            this.scrollTo(s, this.animScroll);
 
985
        }
 
986
    },
 
987
 
 
988
    // private
 
989
    updateScrollButtons : function(){
 
990
        var pos = this.getScrollPos();
 
991
        this.scrollLeft[pos == 0 ? 'addClass' : 'removeClass']('x-tab-scroller-left-disabled');
 
992
        this.scrollRight[pos >= (this.getScrollWidth()-this.getScrollArea()) ? 'addClass' : 'removeClass']('x-tab-scroller-right-disabled');
 
993
    },
 
994
 
 
995
    // private
 
996
    beforeDestroy : function() {
 
997
        if(this.items){
 
998
            this.items.each(function(item){
 
999
                if(item && item.tabEl){
 
1000
                    Ext.get(item.tabEl).removeAllListeners();
 
1001
                    item.tabEl = null;
 
1002
                }
 
1003
            }, this);
 
1004
        }
 
1005
        if(this.strip){
 
1006
            this.strip.removeAllListeners();
 
1007
        }
 
1008
        Ext.TabPanel.superclass.beforeDestroy.apply(this);
 
1009
    }
 
1010
 
 
1011
    /**
 
1012
     * @cfg {Boolean} collapsible
 
1013
     * @hide
 
1014
     */
 
1015
    /**
 
1016
     * @cfg {String} header
 
1017
     * @hide
 
1018
     */
 
1019
    /**
 
1020
     * @cfg {Boolean} headerAsText
 
1021
     * @hide
 
1022
     */
 
1023
    /**
 
1024
     * @property header
 
1025
     * @hide
 
1026
     */
 
1027
    /**
 
1028
     * @property title
 
1029
     * @hide
 
1030
     */
 
1031
    /**
 
1032
     * @cfg {Array} tools
 
1033
     * @hide
 
1034
     */
 
1035
    /**
 
1036
     * @cfg {Array} toolTemplate
 
1037
     * @hide
 
1038
     */
 
1039
    /**
 
1040
     * @cfg {Boolean} hideCollapseTool
 
1041
     * @hide
 
1042
     */
 
1043
    /**
 
1044
     * @cfg {Boolean} titleCollapse
 
1045
     * @hide
 
1046
     */
 
1047
    /**
 
1048
     * @cfg {Boolean} collapsed
 
1049
     * @hide
 
1050
     */
 
1051
    /**
 
1052
     * @cfg {String} layout
 
1053
     * @hide
 
1054
     */
 
1055
});
 
1056
Ext.reg('tabpanel', Ext.TabPanel);
 
1057
 
 
1058
/**
 
1059
 * See {@link #setActiveTab}. Sets the specified tab as the active tab. This method fires
 
1060
 * the {@link #beforetabchange} event which can <tt>return false</tt> to cancel the tab change.
 
1061
 * @param {String/Panel} tab The id or tab Panel to activate
 
1062
 * @method activate
 
1063
 */
 
1064
Ext.TabPanel.prototype.activate = Ext.TabPanel.prototype.setActiveTab;
 
1065
 
 
1066
// private utility class used by TabPanel
 
1067
Ext.TabPanel.AccessStack = function(){
 
1068
    var items = [];
 
1069
    return {
 
1070
        add : function(item){
 
1071
            items.push(item);
 
1072
            if(items.length > 10){
 
1073
                items.shift();
 
1074
            }
 
1075
        },
 
1076
 
 
1077
        remove : function(item){
 
1078
            var s = [];
 
1079
            for(var i = 0, len = items.length; i < len; i++) {
 
1080
                if(items[i] != item){
 
1081
                    s.push(items[i]);
 
1082
                }
 
1083
            }
 
1084
            items = s;
 
1085
        },
 
1086
 
 
1087
        next : function(){
 
1088
            return items.pop();
 
1089
        }
 
1090
    };
 
1091
};
 
 
b'\\ No newline at end of file'