Tab2.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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-Tab'>/**
  19. </span> * @author Ed Spencer
  20. *
  21. * Represents a single Tab in a {@link Ext.tab.Panel TabPanel}. A Tab is simply a slightly customized {@link Ext.button.Button Button},
  22. * styled to look like a tab. Tabs are optionally closable, and can also be disabled. 99% of the time you will not
  23. * need to create Tabs manually as the framework does so automatically when you use a {@link Ext.tab.Panel TabPanel}
  24. */
  25. Ext.define('Ext.tab.Tab', {
  26. extend: 'Ext.button.Button',
  27. alias: 'widget.tab',
  28. requires: [
  29. 'Ext.layout.component.Tab',
  30. 'Ext.util.KeyNav'
  31. ],
  32. componentLayout: 'tab',
  33. <span id='Ext-tab-Tab-property-isTab'> /**
  34. </span> * @property {Boolean} isTab
  35. * `true` in this class to identify an object as an instantiated Tab, or subclass thereof.
  36. */
  37. isTab: true,
  38. baseCls: Ext.baseCSSPrefix + 'tab',
  39. <span id='Ext-tab-Tab-cfg-activeCls'> /**
  40. </span> * @cfg {String} activeCls
  41. * The CSS class to be applied to a Tab when it is active.
  42. * Providing your own CSS for this class enables you to customize the active state.
  43. */
  44. activeCls: 'active',
  45. <span id='Ext-tab-Tab-cfg-disabledCls'> /**
  46. </span> * @cfg {String} [disabledCls='x-tab-disabled']
  47. * The CSS class to be applied to a Tab when it is disabled.
  48. */
  49. <span id='Ext-tab-Tab-cfg-closableCls'> /**
  50. </span> * @cfg {String} closableCls
  51. * The CSS class which is added to the tab when it is closable
  52. */
  53. closableCls: 'closable',
  54. <span id='Ext-tab-Tab-cfg-closable'> /**
  55. </span> * @cfg {Boolean} closable
  56. * True to make the Tab start closable (the close icon will be visible).
  57. */
  58. closable: true,
  59. //&lt;locale&gt;
  60. <span id='Ext-tab-Tab-cfg-closeText'> /**
  61. </span> * @cfg {String} closeText
  62. * The accessible text label for the close button link; only used when {@link #cfg-closable} = true.
  63. */
  64. closeText: 'Close Tab',
  65. //&lt;/locale&gt;
  66. <span id='Ext-tab-Tab-property-active'> /**
  67. </span> * @property {Boolean} active
  68. * Indicates that this tab is currently active. This is NOT a public configuration.
  69. * @readonly
  70. */
  71. active: false,
  72. <span id='Ext-tab-Tab-property-closable'> /**
  73. </span> * @property {Boolean} closable
  74. * True if the tab is currently closable
  75. */
  76. childEls: [
  77. 'closeEl'
  78. ],
  79. scale: false,
  80. position: 'top',
  81. initComponent: function() {
  82. var me = this;
  83. me.addEvents(
  84. <span id='Ext-tab-Tab-event-activate'> /**
  85. </span> * @event activate
  86. * Fired when the tab is activated.
  87. * @param {Ext.tab.Tab} this
  88. */
  89. 'activate',
  90. <span id='Ext-tab-Tab-event-deactivate'> /**
  91. </span> * @event deactivate
  92. * Fired when the tab is deactivated.
  93. * @param {Ext.tab.Tab} this
  94. */
  95. 'deactivate',
  96. <span id='Ext-tab-Tab-event-beforeclose'> /**
  97. </span> * @event beforeclose
  98. * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
  99. * false from any listener to stop the close event being fired
  100. * @param {Ext.tab.Tab} tab The Tab object
  101. */
  102. 'beforeclose',
  103. <span id='Ext-tab-Tab-event-close'> /**
  104. </span> * @event close
  105. * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
  106. * @param {Ext.tab.Tab} tab The Tab object
  107. */
  108. 'close'
  109. );
  110. me.callParent(arguments);
  111. if (me.card) {
  112. me.setCard(me.card);
  113. }
  114. },
  115. getTemplateArgs: function() {
  116. var me = this,
  117. result = me.callParent();
  118. result.closable = me.closable;
  119. result.closeText = me.closeText;
  120. return result;
  121. },
  122. beforeRender: function() {
  123. var me = this,
  124. tabBar = me.up('tabbar'),
  125. tabPanel = me.up('tabpanel');
  126. me.callParent();
  127. me.addClsWithUI(me.position);
  128. // Set all the state classNames, as they need to include the UI
  129. // me.disabledCls = me.getClsWithUIs('disabled');
  130. me.syncClosableUI();
  131. // Propagate minTabWidth and maxTabWidth settings from the owning TabBar then TabPanel
  132. if (!me.minWidth) {
  133. me.minWidth = (tabBar) ? tabBar.minTabWidth : me.minWidth;
  134. if (!me.minWidth &amp;&amp; tabPanel) {
  135. me.minWidth = tabPanel.minTabWidth;
  136. }
  137. if (me.minWidth &amp;&amp; me.iconCls) {
  138. me.minWidth += 25;
  139. }
  140. }
  141. if (!me.maxWidth) {
  142. me.maxWidth = (tabBar) ? tabBar.maxTabWidth : me.maxWidth;
  143. if (!me.maxWidth &amp;&amp; tabPanel) {
  144. me.maxWidth = tabPanel.maxTabWidth;
  145. }
  146. }
  147. },
  148. onRender: function() {
  149. var me = this;
  150. me.callParent(arguments);
  151. me.keyNav = new Ext.util.KeyNav(me.el, {
  152. enter: me.onEnterKey,
  153. del: me.onDeleteKey,
  154. scope: me
  155. });
  156. },
  157. // inherit docs
  158. enable : function(silent) {
  159. var me = this;
  160. me.callParent(arguments);
  161. me.removeClsWithUI(me.position + '-disabled');
  162. return me;
  163. },
  164. // inherit docs
  165. disable : function(silent) {
  166. var me = this;
  167. me.callParent(arguments);
  168. me.addClsWithUI(me.position + '-disabled');
  169. return me;
  170. },
  171. onDestroy: function() {
  172. var me = this;
  173. Ext.destroy(me.keyNav);
  174. delete me.keyNav;
  175. me.callParent(arguments);
  176. },
  177. <span id='Ext-tab-Tab-method-setClosable'> /**
  178. </span> * Sets the tab as either closable or not.
  179. * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
  180. * close button will appear on the tab)
  181. */
  182. setClosable: function(closable) {
  183. var me = this;
  184. // Closable must be true if no args
  185. closable = (!arguments.length || !!closable);
  186. if (me.closable != closable) {
  187. me.closable = closable;
  188. // set property on the user-facing item ('card'):
  189. if (me.card) {
  190. me.card.closable = closable;
  191. }
  192. me.syncClosableUI();
  193. if (me.rendered) {
  194. me.syncClosableElements();
  195. // Tab will change width to accommodate close icon
  196. me.updateLayout();
  197. }
  198. }
  199. },
  200. <span id='Ext-tab-Tab-method-syncClosableElements'> /**
  201. </span> * This method ensures that the closeBtn element exists or not based on 'closable'.
  202. * @private
  203. */
  204. syncClosableElements: function () {
  205. var me = this,
  206. closeEl = me.closeEl;
  207. if (me.closable) {
  208. if (!closeEl) {
  209. me.closeEl = me.btnWrap.insertSibling({
  210. tag: 'a',
  211. cls: me.baseCls + '-close-btn',
  212. href: '#',
  213. title: me.closeText
  214. }, 'after');
  215. }
  216. } else if (closeEl) {
  217. closeEl.remove();
  218. delete me.closeEl;
  219. }
  220. },
  221. <span id='Ext-tab-Tab-method-syncClosableUI'> /**
  222. </span> * This method ensures that the UI classes are added or removed based on 'closable'.
  223. * @private
  224. */
  225. syncClosableUI: function () {
  226. var me = this,
  227. classes = [me.closableCls, me.closableCls + '-' + me.position];
  228. if (me.closable) {
  229. me.addClsWithUI(classes);
  230. } else {
  231. me.removeClsWithUI(classes);
  232. }
  233. },
  234. <span id='Ext-tab-Tab-method-setCard'> /**
  235. </span> * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
  236. * belongs to and would not need to be done by the developer
  237. * @param {Ext.Component} card The card to set
  238. */
  239. setCard: function(card) {
  240. var me = this;
  241. me.card = card;
  242. me.setText(me.title || card.title);
  243. me.setIconCls(me.iconCls || card.iconCls);
  244. me.setIcon(me.icon || card.icon);
  245. },
  246. <span id='Ext-tab-Tab-method-onCloseClick'> /**
  247. </span> * @private
  248. * Listener attached to click events on the Tab's close button
  249. */
  250. onCloseClick: function() {
  251. var me = this;
  252. if (me.fireEvent('beforeclose', me) !== false) {
  253. if (me.tabBar) {
  254. if (me.tabBar.closeTab(me) === false) {
  255. // beforeclose on the panel vetoed the event, stop here
  256. return;
  257. }
  258. } else {
  259. // if there's no tabbar, fire the close event
  260. me.fireClose();
  261. }
  262. }
  263. },
  264. <span id='Ext-tab-Tab-method-fireClose'> /**
  265. </span> * Fires the close event on the tab.
  266. * @private
  267. */
  268. fireClose: function(){
  269. this.fireEvent('close', this);
  270. },
  271. <span id='Ext-tab-Tab-method-onEnterKey'> /**
  272. </span> * @private
  273. */
  274. onEnterKey: function(e) {
  275. var me = this;
  276. if (me.tabBar) {
  277. me.tabBar.onClick(e, me.el);
  278. }
  279. },
  280. <span id='Ext-tab-Tab-method-onDeleteKey'> /**
  281. </span> * @private
  282. */
  283. onDeleteKey: function(e) {
  284. if (this.closable) {
  285. this.onCloseClick();
  286. }
  287. },
  288. // @private
  289. activate : function(supressEvent) {
  290. var me = this;
  291. me.active = true;
  292. me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
  293. if (supressEvent !== true) {
  294. me.fireEvent('activate', me);
  295. }
  296. },
  297. // @private
  298. deactivate : function(supressEvent) {
  299. var me = this;
  300. me.active = false;
  301. me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
  302. if (supressEvent !== true) {
  303. me.fireEvent('deactivate', me);
  304. }
  305. }
  306. });
  307. </pre>
  308. </body>
  309. </html>