13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-tab-Bar'>/**
</span> * @author Ed Spencer
 * TabBar is used internally by a {@link Ext.tab.Panel TabPanel} and typically should not need to be created manually.
 * The tab bar automatically removes the default title provided by {@link Ext.panel.Header}
 */
Ext.define('Ext.tab.Bar', {
    extend: 'Ext.panel.Header',
    alias: 'widget.tabbar',
<span id='Ext-tab-Bar-cfg-baseCls'>    baseCls: Ext.baseCSSPrefix + 'tab-bar',
</span>
    requires: [
        'Ext.tab.Tab',
        'Ext.util.Point'
    ],
 
<span id='Ext-tab-Bar-property-isTabBar'>    /**
</span>     * @property {Boolean} isTabBar
     * `true` in this class to identify an object as an instantiated Tab Bar, or subclass thereof.
     */
    isTabBar: true,
    
<span id='Ext-tab-Bar-cfg-title'>    /**
</span>     * @cfg {String} title @hide
     */
    
<span id='Ext-tab-Bar-cfg-iconCls'>    /**
</span>     * @cfg {String} iconCls @hide
     */
 
<span id='Ext-tab-Bar-cfg-defaultType'>    // @private
</span>    defaultType: 'tab',
 
<span id='Ext-tab-Bar-cfg-plain'>    /**
</span>     * @cfg {Boolean} plain
     * True to not show the full background on the tabbar
     */
    plain: false,
 
<span id='Ext-tab-Bar-property-childEls'>    childEls: [
</span>        'body', 'strip'
    ],
 
<span id='Ext-tab-Bar-cfg-renderTpl'>    // @private
</span>    renderTpl: [
        '&lt;div id=&quot;{id}-body&quot; class=&quot;{baseCls}-body {bodyCls} {bodyTargetCls}{childElCls}&lt;tpl if=&quot;ui&quot;&gt; {baseCls}-body-{ui}&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-body-{parent.ui}-{.}&lt;/tpl&gt;&lt;/tpl&gt;&quot;&lt;tpl if=&quot;bodyStyle&quot;&gt; style=&quot;{bodyStyle}&quot;&lt;/tpl&gt;&gt;',
            '{%this.renderContainer(out,values)%}',
        '&lt;/div&gt;',
        '&lt;div id=&quot;{id}-strip&quot; class=&quot;{baseCls}-strip {baseCls}-strip-{dock}{childElCls}',
            '&lt;tpl if=&quot;ui&quot;&gt; {baseCls}-strip-{ui}',
                '&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-strip-{parent.ui}-{.}&lt;/tpl&gt;',
            '&lt;/tpl&gt;&quot;&gt;',
        '&lt;/div&gt;'
    ],
 
<span id='Ext-tab-Bar-cfg-minTabWidth'>    /**
</span>     * @cfg {Number} minTabWidth
     * The minimum width for a tab in this tab Bar. Defaults to the tab Panel's {@link Ext.tab.Panel#minTabWidth minTabWidth} value.
     * @deprecated This config is deprecated. It is much easier to use the {@link Ext.tab.Panel#minTabWidth minTabWidth} config on the TabPanel.
     */
 
<span id='Ext-tab-Bar-cfg-maxTabWidth'>    /**
</span>     * @cfg {Number} maxTabWidth
     * The maximum width for a tab in this tab Bar. Defaults to the tab Panel's {@link Ext.tab.Panel#maxTabWidth maxTabWidth} value.
     * @deprecated This config is deprecated. It is much easier to use the {@link Ext.tab.Panel#maxTabWidth maxTabWidth} config on the TabPanel.
     */
 
    _reverseDockNames: {
        left: 'right',
        right: 'left'
    },
 
<span id='Ext-tab-Bar-method-initComponent'>    // @private
</span>    initComponent: function() {
        var me = this;
 
        if (me.plain) {
            me.addCls(me.baseCls + '-plain');
        }
 
        me.addClsWithUI(me.orientation);
 
        me.addEvents(
<span id='Ext-tab-Bar-event-change'>            /**
</span>             * @event change
             * Fired when the currently-active tab has changed
             * @param {Ext.tab.Bar} tabBar The TabBar
             * @param {Ext.tab.Tab} tab The new Tab
             * @param {Ext.Component} card The card that was just shown in the TabPanel
             */
            'change'
        );
 
        // Element onClick listener added by Header base class
        me.callParent(arguments);
        Ext.merge(me.layout, me.initialConfig.layout);
 
        // TabBar must override the Header's align setting.
        me.layout.align = (me.orientation == 'vertical') ? 'left' : 'top';
        me.layout.overflowHandler = new Ext.layout.container.boxOverflow.Scroller(me.layout);
 
        me.remove(me.titleCmp);
        delete me.titleCmp;
 
        Ext.apply(me.renderData, {
            bodyCls: me.bodyCls,
            dock: me.dock
        });
    },
 
<span id='Ext-tab-Bar-method-onRender'>    onRender: function() {
</span>        var me = this;
 
        me.callParent();
 
        if (me.orientation === 'vertical' &amp;&amp; (Ext.isIE8 || Ext.isIE9) &amp;&amp; Ext.isStrict) {
            me.el.on({
                mousemove: me.onMouseMove, 
                scope: me
            });
        }
    },
 
<span id='Ext-tab-Bar-method-afterRender'>    afterRender: function() {
</span>        var layout = this.layout;
 
        this.callParent();
        if (Ext.isIE9 &amp;&amp; Ext.isStrict &amp;&amp; this.orientation === 'vertical') {
            // EXTJSIV-8765: focusing a vertically-oriented tab in IE9 strict can cause
            // the innerCt to scroll if the tabs have bordering.  
            layout.innerCt.on('scroll', function() {
                layout.innerCt.dom.scrollLeft = 0;
            });
        }
    },
 
<span id='Ext-tab-Bar-method-afterLayout'>    afterLayout: function() {
</span>        this.adjustTabPositions();
        this.callParent(arguments);
    },
 
<span id='Ext-tab-Bar-method-adjustTabPositions'>    adjustTabPositions: function() {
</span>        var items = this.items.items,
            i = items.length,
            tab;
 
        // When tabs are rotated vertically we don't have a reliable way to position
        // them using CSS in modern browsers.  This is because of the way transform-orign
        // works - it requires the width to be known, and the width is not known in css.
        // Consequently we have to make an adjustment to the tab's position in these browsers.
        // This is similar to what we do in Ext.panel.Header#adjustTitlePosition
        if (!Ext.isIE9m) {
            if (this.dock === 'right') {
                // rotated 90 degrees around using the top left corner as the axis.
                // tabs need to be shifted to the right by their width
                while (i--) {
                    tab = items[i];
                    if (tab.isVisible()) {
                        tab.el.setStyle('left', tab.lastBox.width + 'px');
                    }
                }
            } else if (this.dock === 'left') {
                // rotated 270 degrees around using the top left corner as the axis.
                // tabs need to be shifted down by their height
                while (i--) {
                    tab = items[i];
                    if (tab.isVisible()) {
                        tab.el.setStyle('left', -tab.lastBox.height + 'px');
                    }
                }
            }
        }
    },
 
<span id='Ext-tab-Bar-method-getLayout'>    getLayout: function() {
</span>        var me = this;
        me.layout.type = (me.orientation === 'horizontal') ? 'hbox' : 'vbox';
        return me.callParent(arguments);
    },
 
<span id='Ext-tab-Bar-method-onAdd'>    // @private
</span>    onAdd: function(tab) {
        tab.position = this.dock;
        this.callParent(arguments);
    },
    
<span id='Ext-tab-Bar-method-onRemove'>    onRemove: function(tab) {
</span>        var me = this;
        
        if (tab === me.previousTab) {
            me.previousTab = null;
        }
        me.callParent(arguments);    
    },
 
<span id='Ext-tab-Bar-method-afterComponentLayout'>    afterComponentLayout : function(width) {
</span>        var me = this,
            needsScroll = me.needsScroll;
        
        me.callParent(arguments);
            
        if (needsScroll) {
            me.layout.overflowHandler.scrollToItem(me.activeTab);
        }    
        delete me.needsScroll;
    },
 
<span id='Ext-tab-Bar-method-onClick'>    // @private
</span>    onClick: function(e, target) {
        var me = this,
            tabPanel = me.tabPanel,
            tabEl, tab, isCloseClick, tabInfo;
 
        if (e.getTarget('.' + Ext.baseCSSPrefix + 'box-scroller')) {
            return;
        }
 
        if (me.orientation === 'vertical' &amp;&amp; (Ext.isIE8 || Ext.isIE9) &amp;&amp; Ext.isStrict) {
            tabInfo = me.getTabInfoFromPoint(e.getXY());
            tab = tabInfo.tab;
            isCloseClick = tabInfo.close;
        } else {
            // The target might not be a valid tab el.
            tabEl = e.getTarget('.' + Ext.tab.Tab.prototype.baseCls);
            tab = tabEl &amp;&amp; Ext.getCmp(tabEl.id);
            isCloseClick = tab &amp;&amp; tab.closeEl &amp;&amp; (target === tab.closeEl.dom);
        }
 
        if (isCloseClick) {
            e.preventDefault();
        }
        if (tab &amp;&amp; tab.isDisabled &amp;&amp; !tab.isDisabled()) {
            if (tab.closable &amp;&amp; isCloseClick) {
                tab.onCloseClick();
            } else {
                if (tabPanel) {
                    // TabPanel will card setActiveTab of the TabBar
                    tabPanel.setActiveTab(tab.card);
                } else {
                    me.setActiveTab(tab);
                }
                tab.focus();
            }
        }
    },
 
<span id='Ext-tab-Bar-method-onMouseMove'>    // private
</span>    onMouseMove: function(e) {
        var me = this,
            overTab = me._overTab,
            tabInfo, tab;
 
        if (e.getTarget('.' + Ext.baseCSSPrefix + 'box-scroller')) {
            return;
        }
 
        tabInfo = me.getTabInfoFromPoint(e.getXY());
        tab = tabInfo.tab;
 
        if (tab !== overTab) {
            if (overTab &amp;&amp; overTab.rendered) {
                overTab.onMouseLeave(e);
                me._overTab = null;
            }
            if (tab) {
                tab.onMouseEnter(e);
                me._overTab = tab;
                if (!tab.disabled) {
                    me.el.setStyle('cursor', 'pointer');
                }
            } else {
                me.el.setStyle('cursor', 'default');
            }
        }
    },
 
<span id='Ext-tab-Bar-method-onMouseLeave'>    onMouseLeave: function(e) {
</span>        var overTab = this._overTab;
 
        if (overTab &amp;&amp; overTab.rendered) {
            overTab.onMouseLeave(e);
        }
    },
 
<span id='Ext-tab-Bar-method-getTabInfoFromPoint'>    // @private
</span>    // in IE8 and IE9 the clickable region of a rotated element is not its new rotated
    // position, but it's original unrotated position.  The result is that rotated tabs do
    // not capture click and mousenter/mosueleave events correctly.  This method accepts
    // an xy position and calculates if the coordinates are within a tab and if they
    // are within the tab's close icon (if any)
    getTabInfoFromPoint: function(xy) {
        var me = this,
            tabs = me.items.items,
            length = tabs.length,
            innerCt = me.layout.innerCt,
            innerCtXY = innerCt.getXY(),
            point = new Ext.util.Point(xy[0], xy[1]),
            i = 0,
            lastBox, tabRegion, closeEl, close, closeXY, closeX, closeY, closeWidth,
            closeHeight, tabX, tabY, tabWidth, tabHeight, closeRegion, isTabReversed,
            direction, tab;
 
        for (; i &lt; length; i++) {
            lastBox = tabs[i].lastBox;
            tabX = innerCtXY[0] + lastBox.x;
            tabY = innerCtXY[1] - innerCt.dom.scrollTop + lastBox.y;
            tabWidth = lastBox.width;
            tabHeight = lastBox.height;
            tabRegion = new Ext.util.Region(
                tabY,
                tabX + tabWidth,
                tabY + tabHeight,
                tabX
            );
            if (tabRegion.contains(point)) {
                tab = tabs[i];
                closeEl = tab.closeEl;
                if (closeEl) {
                    closeXY = closeEl.getXY();
                    closeWidth = closeEl.getWidth();
                    closeHeight = closeEl.getHeight();
                    // Read the dom to determine if the contents of the tab are reversed
                    // (rotated 180 degrees).  If so, we can cache the result becuase
                    // it's safe to assume all tabs in the tabbar will be the same
                    if (me._isTabReversed === undefined) {
                        me._isTabReversed = isTabReversed =
                        // use currentStyle because getComputedStyle won't get the
                        // filter property in IE9
                        (tab.btnWrap.dom.currentStyle.filter.indexOf('rotation=2') !== -1);
                    }
 
                    direction = isTabReversed ? this._reverseDockNames[me.dock] : me.dock;
 
                    if (direction === 'right') {
                        closeX = tabX + tabWidth - ((closeXY[1] - tabY) + closeEl.getHeight()); 
                        closeY = tabY + (closeXY[0] - tabX); 
                    } else {
                        closeX = tabX + (closeXY[1] - tabY);
                        closeY = tabY + tabX + tabHeight - closeXY[0] - closeEl.getWidth();
                    }
                        
                    closeRegion = new Ext.util.Region(
                        closeY,
                        closeX + closeWidth,
                        closeY + closeHeight,
                        closeX
                    );
 
                    close = closeRegion.contains(point);
                }
                break;
            }
        }
            
        return {
            tab: tab,
            close: close
        };
    },
 
<span id='Ext-tab-Bar-method-closeTab'>    /**
</span>     * @private
     * Closes the given tab by removing it from the TabBar and removing the corresponding card from the TabPanel
     * @param {Ext.tab.Tab} toClose The tab to close
     */
    closeTab: function(toClose) {
        var me = this,
            card = toClose.card,
            tabPanel = me.tabPanel,
            toActivate;
 
        if (card &amp;&amp; card.fireEvent('beforeclose', card) === false) {
            return false;
        }
        
        // If we are closing the active tab, revert to the previously active tab (or the previous or next enabled sibling if
        // there *is* no previously active tab, or the previously active tab is the one that's being closed or the previously
        // active tab has since been disabled)
        toActivate = me.findNextActivatable(toClose);
 
        // We are going to remove the associated card, and then, if that was sucessful, remove the Tab,
        // And then potentially activate another Tab. We should not layout for each of these operations.
        Ext.suspendLayouts();
 
        if (tabPanel &amp;&amp; card) {
            // Remove the ownerCt so the tab doesn't get destroyed if the remove is successful
            // We need this so we can have the tab fire it's own close event.
            delete toClose.ownerCt;
            
            // we must fire 'close' before removing the card from panel, otherwise
            // the event will no loger have any listener
            card.fireEvent('close', card);
            tabPanel.remove(card);
            
            // Remove succeeded
            if (!tabPanel.getComponent(card)) {
                /*
                 * Force the close event to fire. By the time this function returns,
                 * the tab is already destroyed and all listeners have been purged
                 * so the tab can't fire itself.
                 */
                toClose.fireClose();
                me.remove(toClose);
            } else {
                // Restore the ownerCt from above
                toClose.ownerCt = me;
                Ext.resumeLayouts(true);
                return false;
            }
        }
 
        // If we are closing the active tab, revert to the previously active tab (or the previous sibling or the nnext sibling)
        if (toActivate) {
            // Our owning TabPanel calls our setActiveTab method, so only call that if this Bar is being used
            // in some other context (unlikely)
            if (tabPanel) {
                tabPanel.setActiveTab(toActivate.card);
            } else {
                me.setActiveTab(toActivate);
            }
            toActivate.focus();
        }
        Ext.resumeLayouts(true);
    },
 
<span id='Ext-tab-Bar-method-findNextActivatable'>    // private - used by TabPanel too.
</span>    // Works out the next tab to activate when one tab is closed.
    findNextActivatable: function(toClose) {
        var me = this;
        if (toClose.active &amp;&amp; me.items.getCount() &gt; 1) {
            return (me.previousTab &amp;&amp; me.previousTab !== toClose &amp;&amp; !me.previousTab.disabled) ? me.previousTab : (toClose.next('tab[disabled=false]') || toClose.prev('tab[disabled=false]'));
        }
    },
 
<span id='Ext-tab-Bar-method-setActiveTab'>    /**
</span>     * @private
     * Marks the given tab as active
     * @param {Ext.tab.Tab} tab The tab to mark active
     * @param {Boolean} initial True if we're setting the tab during setup
     */
    setActiveTab: function(tab, initial) {
        var me = this;
 
        if (!tab.disabled &amp;&amp; tab !== me.activeTab) {
            if (me.activeTab) {
                if (me.activeTab.isDestroyed) {
                    me.previousTab = null;
                } else {
                    me.previousTab = me.activeTab;
                    me.activeTab.deactivate();
                }
            }
            tab.activate();
 
            me.activeTab = tab;
            me.needsScroll = true;
            
            // We don't fire the change event when setting the first tab.
            // Also no need to run a layout
            if (!initial) {
                me.fireEvent('change', me, tab, tab.card);
                // Ensure that after the currently in progress layout, the active tab is scrolled into view
                me.updateLayout();
            }
        }
    }
});
</pre>
</body>
</html>