tabs-adv.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Ext.Loader.setConfig({enabled: true});
  2. Ext.Loader.setPath('Ext.ux', '../ux/');
  3. Ext.require([
  4. 'Ext.tab.*',
  5. 'Ext.ux.TabCloseMenu'
  6. ]);
  7. Ext.onReady(function() {
  8. var currentItem;
  9. var tabs = Ext.widget('tabpanel', {
  10. renderTo: 'tabs',
  11. resizeTabs: true,
  12. enableTabScroll: true,
  13. width: 600,
  14. height: 250,
  15. defaults: {
  16. autoScroll: true,
  17. bodyPadding: 10
  18. },
  19. items: [{
  20. title: 'Tab 1',
  21. iconCls: 'tabs',
  22. html: 'Tab Body<br/><br/>' + Ext.example.bogusMarkup,
  23. closable: true
  24. }],
  25. plugins: Ext.create('Ext.ux.TabCloseMenu', {
  26. extraItemsTail: [
  27. '-',
  28. {
  29. text: 'Closable',
  30. checked: true,
  31. hideOnClick: true,
  32. handler: function (item) {
  33. currentItem.tab.setClosable(item.checked);
  34. }
  35. },
  36. '-',
  37. {
  38. text: 'Enabled',
  39. checked: true,
  40. hideOnClick: true,
  41. handler: function(item) {
  42. currentItem.tab.setDisabled(!item.checked);
  43. }
  44. }
  45. ],
  46. listeners: {
  47. aftermenu: function () {
  48. currentItem = null;
  49. },
  50. beforemenu: function (menu, item) {
  51. menu.child('[text="Closable"]').setChecked(item.closable);
  52. menu.child('[text="Enabled"]').setChecked(!item.tab.isDisabled());
  53. currentItem = item;
  54. }
  55. }
  56. })
  57. });
  58. // tab generation code
  59. var index = 0;
  60. while(index < 3) {
  61. addTab(index % 2);
  62. }
  63. function addTab (closable) {
  64. ++index;
  65. tabs.add({
  66. closable: !!closable,
  67. html: 'Tab Body ' + index + '<br/><br/>' + Ext.example.bogusMarkup,
  68. iconCls: 'tabs',
  69. title: 'New Tab ' + index
  70. }).show();
  71. }
  72. Ext.widget('button', {
  73. iconCls: 'new-tab',
  74. renderTo: 'addButtonCt',
  75. text: 'Add Closable Tab',
  76. handler: function () {
  77. addTab(true);
  78. }
  79. });
  80. Ext.widget('button', {
  81. iconCls:'new-tab',
  82. renderTo: 'addButtonCt',
  83. style: 'margin-left: 8px;',
  84. text: 'Add Unclosable Tab',
  85. handler: function () {
  86. addTab(false);
  87. }
  88. });
  89. });