3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">
10 Ext.ux.TabScrollerMenu = Ext.extend(Object, {
13 menuPrefixText : 'Items',
14 constructor : function(config) {
15 config = config || {};
16 Ext.apply(this, config);
18 init : function(tabPanel) {
19 Ext.apply(tabPanel, this.tabPanelMethods);
21 tabPanel.tabScrollerMenu = this;
29 var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
30 tabPanel.createScrollers = newFn;
35 // private && sequeneced
36 createPanelsMenu : function() {
37 var h = this.stripWrap.dom.offsetHeight;
39 //move the right menu item to the left 18px
40 var rtScrBtn = this.header.dom.firstChild;
41 Ext.fly(rtScrBtn).applyStyles({
45 var stripWrap = Ext.get(this.strip.dom.parentNode);
46 stripWrap.applyStyles({
47 'margin-right' : '36px'
50 // Add the new righthand menu
51 var scrollMenu = this.header.insertFirst({
52 cls:'x-tab-tabmenu-right'
54 scrollMenu.setHeight(h);
55 scrollMenu.addClassOnOver('x-tab-tabmenu-over');
56 scrollMenu.on('click', this.showTabsMenu, this);
58 this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
62 this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
68 getPageSize : function() {
72 setPageSize : function(pageSize) {
73 this.pageSize = pageSize;
76 getMaxText : function() {
80 setMaxText : function(t) {
83 getMenuPrefixText : function() {
84 return this.menuPrefixText;
86 setMenuPrefixText : function(t) {
87 this.menuPrefixText = t;
89 // private && applied to the tab panel itself.
91 // all execute within the scope of the tab panel
93 showTabsMenu : function(e) {
94 if (! this.tabsMenu) {
95 this.tabsMenu = new Ext.menu.Menu();
96 this.on('beforedestroy', this.tabsMenu.destroy, this.tabsMenu);
99 this.tabsMenu.removeAll();
101 this.generateTabMenuItems();
103 var target = Ext.get(e.getTarget());
104 var xy = target.getXY();
106 //Y param + 24 pixels
109 this.tabsMenu.showAt(xy);
112 generateTabMenuItems : function() {
113 var curActive = this.getActiveTab();
114 var totalItems = this.items.getCount();
115 var pageSize = this.tabScrollerMenu.getPageSize();
118 if (totalItems > pageSize) {
119 var numSubMenus = Math.floor(totalItems / pageSize);
120 var remainder = totalItems % pageSize;
122 // Loop through all of the items and create submenus in chunks of 10
123 for (var i = 0 ; i < numSubMenus; i++) {
124 var curPage = (i + 1) * pageSize;
128 for (var x = 0; x < pageSize; x++) {
129 index = x + curPage - pageSize;
130 var item = this.items.get(index);
131 menuItems.push(this.autoGenMenuItem(item));
135 text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
142 var start = numSubMenus * pageSize;
144 for (var i = start ; i < totalItems; i ++ ) {
145 var item = this.items.get(i);
146 menuItems.push(this.autoGenMenuItem(item));
151 text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
159 this.items.each(function(item) {
160 if (item.id != curActive.id && ! item.hidden) {
161 menuItems.push(this.autoGenMenuItem(item));
167 autoGenMenuItem : function(item) {
168 var maxText = this.tabScrollerMenu.getMaxText();
169 var text = Ext.util.Format.ellipsis(item.title, maxText);
173 handler : this.showTabFromMenu,
175 disabled : item.disabled,
177 iconCls : item.iconCls
182 showTabFromMenu : function(menuItem) {
183 this.setActiveTab(menuItem.tabToShow);