Bar.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-tab-Bar'>/**
  19. </span> * @author Ed Spencer
  20. * TabBar is used internally by a {@link Ext.tab.Panel TabPanel} and typically should not need to be created manually.
  21. * The tab bar automatically removes the default title provided by {@link Ext.panel.Header}
  22. */
  23. Ext.define('Ext.tab.Bar', {
  24. extend: 'Ext.panel.Header',
  25. alias: 'widget.tabbar',
  26. baseCls: Ext.baseCSSPrefix + 'tab-bar',
  27. requires: ['Ext.tab.Tab'],
  28. <span id='Ext-tab-Bar-property-isTabBar'> /**
  29. </span> * @property {Boolean} isTabBar
  30. * `true` in this class to identify an objact as an instantiated Tab Bar, or subclass thereof.
  31. */
  32. isTabBar: true,
  33. <span id='Ext-tab-Bar-cfg-title'> /**
  34. </span> * @cfg {String} title @hide
  35. */
  36. <span id='Ext-tab-Bar-cfg-iconCls'> /**
  37. </span> * @cfg {String} iconCls @hide
  38. */
  39. // @private
  40. defaultType: 'tab',
  41. <span id='Ext-tab-Bar-cfg-plain'> /**
  42. </span> * @cfg {Boolean} plain
  43. * True to not show the full background on the tabbar
  44. */
  45. plain: false,
  46. childEls: [
  47. 'body', 'strip'
  48. ],
  49. // @private
  50. renderTpl: [
  51. '&lt;div id=&quot;{id}-body&quot; class=&quot;{baseCls}-body {bodyCls}&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;',
  52. '{%this.renderContainer(out,values)%}',
  53. '&lt;/div&gt;',
  54. '&lt;div id=&quot;{id}-strip&quot; class=&quot;{baseCls}-strip&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;'
  55. ],
  56. <span id='Ext-tab-Bar-cfg-minTabWidth'> /**
  57. </span> * @cfg {Number} minTabWidth
  58. * The minimum width for a tab in this tab Bar. Defaults to the tab Panel's {@link Ext.tab.Panel#minTabWidth minTabWidth} value.
  59. * @deprecated This config is deprecated. It is much easier to use the {@link Ext.tab.Panel#minTabWidth minTabWidth} config on the TabPanel.
  60. */
  61. <span id='Ext-tab-Bar-cfg-maxTabWidth'> /**
  62. </span> * @cfg {Number} maxTabWidth
  63. * The maximum width for a tab in this tab Bar. Defaults to the tab Panel's {@link Ext.tab.Panel#maxTabWidth maxTabWidth} value.
  64. * @deprecated This config is deprecated. It is much easier to use the {@link Ext.tab.Panel#maxTabWidth maxTabWidth} config on the TabPanel.
  65. */
  66. // @private
  67. initComponent: function() {
  68. var me = this;
  69. if (me.plain) {
  70. me.setUI(me.ui + '-plain');
  71. }
  72. me.addClsWithUI(me.dock);
  73. me.addEvents(
  74. <span id='Ext-tab-Bar-event-change'> /**
  75. </span> * @event change
  76. * Fired when the currently-active tab has changed
  77. * @param {Ext.tab.Bar} tabBar The TabBar
  78. * @param {Ext.tab.Tab} tab The new Tab
  79. * @param {Ext.Component} card The card that was just shown in the TabPanel
  80. */
  81. 'change'
  82. );
  83. // Element onClick listener added by Header base class
  84. me.callParent(arguments);
  85. // TabBar must override the Header's align setting.
  86. me.layout.align = (me.orientation == 'vertical') ? 'left' : 'top';
  87. me.layout.overflowHandler = new Ext.layout.container.boxOverflow.Scroller(me.layout);
  88. me.remove(me.titleCmp);
  89. delete me.titleCmp;
  90. Ext.apply(me.renderData, {
  91. bodyCls: me.bodyCls
  92. });
  93. },
  94. getLayout: function() {
  95. var me = this;
  96. me.layout.type = (me.dock === 'top' || me.dock === 'bottom') ? 'hbox' : 'vbox';
  97. return me.callParent(arguments);
  98. },
  99. // @private
  100. onAdd: function(tab) {
  101. tab.position = this.dock;
  102. this.callParent(arguments);
  103. },
  104. onRemove: function(tab) {
  105. var me = this;
  106. if (tab === me.previousTab) {
  107. me.previousTab = null;
  108. }
  109. me.callParent(arguments);
  110. },
  111. afterComponentLayout : function(width) {
  112. this.callParent(arguments);
  113. this.strip.setWidth(width);
  114. },
  115. // @private
  116. onClick: function(e, target) {
  117. // The target might not be a valid tab el.
  118. var me = this,
  119. tabEl = e.getTarget('.' + Ext.tab.Tab.prototype.baseCls),
  120. tab = tabEl &amp;&amp; Ext.getCmp(tabEl.id),
  121. tabPanel = me.tabPanel,
  122. isCloseClick = tab &amp;&amp; tab.closeEl &amp;&amp; (target === tab.closeEl.dom);
  123. if (isCloseClick) {
  124. e.preventDefault();
  125. }
  126. if (tab &amp;&amp; tab.isDisabled &amp;&amp; !tab.isDisabled()) {
  127. if (tab.closable &amp;&amp; isCloseClick) {
  128. tab.onCloseClick();
  129. } else {
  130. if (tabPanel) {
  131. // TabPanel will card setActiveTab of the TabBar
  132. tabPanel.setActiveTab(tab.card);
  133. } else {
  134. me.setActiveTab(tab);
  135. }
  136. tab.focus();
  137. }
  138. }
  139. },
  140. <span id='Ext-tab-Bar-method-closeTab'> /**
  141. </span> * @private
  142. * Closes the given tab by removing it from the TabBar and removing the corresponding card from the TabPanel
  143. * @param {Ext.tab.Tab} toClose The tab to close
  144. */
  145. closeTab: function(toClose) {
  146. var me = this,
  147. card = toClose.card,
  148. tabPanel = me.tabPanel,
  149. toActivate;
  150. if (card &amp;&amp; card.fireEvent('beforeclose', card) === false) {
  151. return false;
  152. }
  153. // If we are closing the active tab, revert to the previously active tab (or the previous or next enabled sibling if
  154. // there *is* no previously active tab, or the previously active tab is the one that's being closed or the previously
  155. // active tab has since been disabled)
  156. toActivate = me.findNextActivatable(toClose);
  157. // We are going to remove the associated card, and then, if that was sucessful, remove the Tab,
  158. // And then potentially activate another Tab. We should not layout for each of these operations.
  159. Ext.suspendLayouts();
  160. if (tabPanel &amp;&amp; card) {
  161. // Remove the ownerCt so the tab doesn't get destroyed if the remove is successful
  162. // We need this so we can have the tab fire it's own close event.
  163. delete toClose.ownerCt;
  164. // we must fire 'close' before removing the card from panel, otherwise
  165. // the event will no loger have any listener
  166. card.fireEvent('close', card);
  167. tabPanel.remove(card);
  168. // Remove succeeded
  169. if (!tabPanel.getComponent(card)) {
  170. /*
  171. * Force the close event to fire. By the time this function returns,
  172. * the tab is already destroyed and all listeners have been purged
  173. * so the tab can't fire itself.
  174. */
  175. toClose.fireClose();
  176. me.remove(toClose);
  177. } else {
  178. // Restore the ownerCt from above
  179. toClose.ownerCt = me;
  180. Ext.resumeLayouts(true);
  181. return false;
  182. }
  183. }
  184. // If we are closing the active tab, revert to the previously active tab (or the previous sibling or the nnext sibling)
  185. if (toActivate) {
  186. // Our owning TabPanel calls our setActiveTab method, so only call that if this Bar is being used
  187. // in some other context (unlikely)
  188. if (tabPanel) {
  189. tabPanel.setActiveTab(toActivate.card);
  190. } else {
  191. me.setActiveTab(toActivate);
  192. }
  193. toActivate.focus();
  194. }
  195. Ext.resumeLayouts(true);
  196. },
  197. // private - used by TabPanel too.
  198. // Works out the next tab to activate when one tab is closed.
  199. findNextActivatable: function(toClose) {
  200. var me = this;
  201. if (toClose.active &amp;&amp; me.items.getCount() &gt; 1) {
  202. 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]'));
  203. }
  204. },
  205. <span id='Ext-tab-Bar-method-setActiveTab'> /**
  206. </span> * @private
  207. * Marks the given tab as active
  208. * @param {Ext.tab.Tab} tab The tab to mark active
  209. */
  210. setActiveTab: function(tab) {
  211. var me = this;
  212. if (!tab.disabled &amp;&amp; tab !== me.activeTab) {
  213. if (me.activeTab) {
  214. if (me.activeTab.isDestroyed) {
  215. me.previousTab = null;
  216. } else {
  217. me.previousTab = me.activeTab;
  218. me.activeTab.deactivate();
  219. }
  220. }
  221. tab.activate();
  222. me.activeTab = tab;
  223. me.fireEvent('change', me, tab, tab.card);
  224. // Ensure that after the currently in progress layout, the active tab is scrolled into view
  225. me.on({
  226. afterlayout: me.afterTabActivate,
  227. scope: me,
  228. single: true
  229. });
  230. me.updateLayout();
  231. }
  232. },
  233. afterTabActivate: function() {
  234. this.layout.overflowHandler.scrollToItem(this.activeTab);
  235. }
  236. });
  237. </pre>
  238. </body>
  239. </html>