Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
5.8 KiB

  1. /*!
  2. * Ext JS Library 3.2.1
  3. * Copyright(c) 2006-2010 Ext JS, Inc.
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. Ext.ns('Ext.ux');
  8. /**
  9. * @class Ext.ux.TabScrollerMenu
  10. * @extends Object
  11. * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
  12. * @constructor
  13. * @param {Object} config Configuration options
  14. * @ptype tabscrollermenu
  15. */
  16. Ext.ux.TabScrollerMenu = Ext.extend(Object, {
  17. /**
  18. * @cfg {Number} pageSize How many items to allow per submenu.
  19. */
  20. pageSize : 10,
  21. /**
  22. * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
  23. */
  24. maxText : 15,
  25. /**
  26. * @cfg {String} menuPrefixText Text to prefix the submenus.
  27. */
  28. menuPrefixText : 'Items',
  29. constructor : function(config) {
  30. config = config || {};
  31. Ext.apply(this, config);
  32. },
  33. //private
  34. init : function(tabPanel) {
  35. Ext.apply(tabPanel, this.parentOverrides);
  36. tabPanel.tabScrollerMenu = this;
  37. var thisRef = this;
  38. tabPanel.on({
  39. render : {
  40. scope : tabPanel,
  41. single : true,
  42. fn : function() {
  43. var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
  44. tabPanel.createScrollers = newFn;
  45. }
  46. }
  47. });
  48. },
  49. // private && sequeneced
  50. createPanelsMenu : function() {
  51. var h = this.stripWrap.dom.offsetHeight;
  52. //move the right menu item to the left 18px
  53. var rtScrBtn = this.header.dom.firstChild;
  54. Ext.fly(rtScrBtn).applyStyles({
  55. right : '18px'
  56. });
  57. var stripWrap = Ext.get(this.strip.dom.parentNode);
  58. stripWrap.applyStyles({
  59. 'margin-right' : '36px'
  60. });
  61. // Add the new righthand menu
  62. var scrollMenu = this.header.insertFirst({
  63. cls:'x-tab-tabmenu-right'
  64. });
  65. scrollMenu.setHeight(h);
  66. scrollMenu.addClassOnOver('x-tab-tabmenu-over');
  67. scrollMenu.on('click', this.showTabsMenu, this);
  68. this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
  69. scrollMenu.show();
  70. });
  71. this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
  72. scrollMenu.hide();
  73. });
  74. },
  75. /**
  76. * Returns an the current page size (this.pageSize);
  77. * @return {Number} this.pageSize The current page size.
  78. */
  79. getPageSize : function() {
  80. return this.pageSize;
  81. },
  82. /**
  83. * Sets the number of menu items per submenu "page size".
  84. * @param {Number} pageSize The page size
  85. */
  86. setPageSize : function(pageSize) {
  87. this.pageSize = pageSize;
  88. },
  89. /**
  90. * Returns the current maxText length;
  91. * @return {Number} this.maxText The current max text length.
  92. */
  93. getMaxText : function() {
  94. return this.maxText;
  95. },
  96. /**
  97. * Sets the maximum text size for each menu item.
  98. * @param {Number} t The max text per each menu item.
  99. */
  100. setMaxText : function(t) {
  101. this.maxText = t;
  102. },
  103. /**
  104. * Returns the current menu prefix text String.;
  105. * @return {String} this.menuPrefixText The current menu prefix text.
  106. */
  107. getMenuPrefixText : function() {
  108. return this.menuPrefixText;
  109. },
  110. /**
  111. * Sets the menu prefix text String.
  112. * @param {String} t The menu prefix text.
  113. */
  114. setMenuPrefixText : function(t) {
  115. this.menuPrefixText = t;
  116. },
  117. // private && applied to the tab panel itself.
  118. parentOverrides : {
  119. // all execute within the scope of the tab panel
  120. // private
  121. showTabsMenu : function(e) {
  122. if (this.tabsMenu) {
  123. this.tabsMenu.destroy();
  124. this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
  125. this.tabsMenu = null;
  126. }
  127. this.tabsMenu = new Ext.menu.Menu();
  128. this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
  129. this.generateTabMenuItems();
  130. var target = Ext.get(e.getTarget());
  131. var xy = target.getXY();
  132. //
  133. //Y param + 24 pixels
  134. xy[1] += 24;
  135. this.tabsMenu.showAt(xy);
  136. },
  137. // private
  138. generateTabMenuItems : function() {
  139. var curActive = this.getActiveTab();
  140. var totalItems = this.items.getCount();
  141. var pageSize = this.tabScrollerMenu.getPageSize();
  142. if (totalItems > pageSize) {
  143. var numSubMenus = Math.floor(totalItems / pageSize);
  144. var remainder = totalItems % pageSize;
  145. // Loop through all of the items and create submenus in chunks of 10
  146. for (var i = 0 ; i < numSubMenus; i++) {
  147. var curPage = (i + 1) * pageSize;
  148. var menuItems = [];
  149. for (var x = 0; x < pageSize; x++) {
  150. index = x + curPage - pageSize;
  151. var item = this.items.get(index);
  152. menuItems.push(this.autoGenMenuItem(item));
  153. }
  154. this.tabsMenu.add({
  155. text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
  156. menu : menuItems
  157. });
  158. }
  159. // remaining items
  160. if (remainder > 0) {
  161. var start = numSubMenus * pageSize;
  162. menuItems = [];
  163. for (var i = start ; i < totalItems; i ++ ) {
  164. var item = this.items.get(i);
  165. menuItems.push(this.autoGenMenuItem(item));
  166. }
  167. this.tabsMenu.add({
  168. text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
  169. menu : menuItems
  170. });
  171. }
  172. }
  173. else {
  174. this.items.each(function(item) {
  175. if (item.id != curActive.id && !item.hidden) {
  176. this.tabsMenu.add(this.autoGenMenuItem(item));
  177. }
  178. }, this);
  179. }
  180. },
  181. // private
  182. autoGenMenuItem : function(item) {
  183. var maxText = this.tabScrollerMenu.getMaxText();
  184. var text = Ext.util.Format.ellipsis(item.title, maxText);
  185. return {
  186. text : text,
  187. handler : this.showTabFromMenu,
  188. scope : this,
  189. disabled : item.disabled,
  190. tabToShow : item,
  191. iconCls : item.iconCls
  192. }
  193. },
  194. // private
  195. showTabFromMenu : function(menuItem) {
  196. this.setActiveTab(menuItem.tabToShow);
  197. }
  198. }
  199. });
  200. Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);