3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
17 * @class Ext.ux.TabScrollerMenu
19 * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
21 * @param {Object} config Configuration options
22 * @ptype tabscrollermenu
24 Ext.ux.TabScrollerMenu = Ext.extend(Object, {
25 <div id="cfg-Ext.ux.TabScrollerMenu-pageSize"></div>/**
26 * @cfg {Number} pageSize How many items to allow per submenu.
29 <div id="cfg-Ext.ux.TabScrollerMenu-maxText"></div>/**
30 * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
33 <div id="cfg-Ext.ux.TabScrollerMenu-menuPrefixText"></div>/**
34 * @cfg {String} menuPrefixText Text to prefix the submenus.
36 menuPrefixText : 'Items',
37 constructor : function(config) {
38 config = config || {};
39 Ext.apply(this, config);
42 init : function(tabPanel) {
43 Ext.apply(tabPanel, this.parentOverrides);
45 tabPanel.tabScrollerMenu = this;
53 var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
54 tabPanel.createScrollers = newFn;
59 // private && sequeneced
60 createPanelsMenu : function() {
61 var h = this.stripWrap.dom.offsetHeight;
63 //move the right menu item to the left 18px
64 var rtScrBtn = this.header.dom.firstChild;
65 Ext.fly(rtScrBtn).applyStyles({
69 var stripWrap = Ext.get(this.strip.dom.parentNode);
70 stripWrap.applyStyles({
71 'margin-right' : '36px'
74 // Add the new righthand menu
75 var scrollMenu = this.header.insertFirst({
76 cls:'x-tab-tabmenu-right'
78 scrollMenu.setHeight(h);
79 scrollMenu.addClassOnOver('x-tab-tabmenu-over');
80 scrollMenu.on('click', this.showTabsMenu, this);
82 this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
86 this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
91 <div id="method-Ext.ux.TabScrollerMenu-getPageSize"></div>/**
92 * Returns an the current page size (this.pageSize);
93 * @return {Number} this.pageSize The current page size.
95 getPageSize : function() {
98 <div id="method-Ext.ux.TabScrollerMenu-setPageSize"></div>/**
99 * Sets the number of menu items per submenu "page size".
100 * @param {Number} pageSize The page size
102 setPageSize : function(pageSize) {
103 this.pageSize = pageSize;
105 <div id="method-Ext.ux.TabScrollerMenu-getMaxText"></div>/**
106 * Returns the current maxText length;
107 * @return {Number} this.maxText The current max text length.
109 getMaxText : function() {
112 <div id="method-Ext.ux.TabScrollerMenu-setMaxText"></div>/**
113 * Sets the maximum text size for each menu item.
114 * @param {Number} t The max text per each menu item.
116 setMaxText : function(t) {
119 <div id="method-Ext.ux.TabScrollerMenu-getMenuPrefixText"></div>/**
120 * Returns the current menu prefix text String.;
121 * @return {String} this.menuPrefixText The current menu prefix text.
123 getMenuPrefixText : function() {
124 return this.menuPrefixText;
126 <div id="method-Ext.ux.TabScrollerMenu-setMenuPrefixText"></div>/**
127 * Sets the menu prefix text String.
128 * @param {String} t The menu prefix text.
130 setMenuPrefixText : function(t) {
131 this.menuPrefixText = t;
133 // private && applied to the tab panel itself.
135 // all execute within the scope of the tab panel
137 showTabsMenu : function(e) {
139 this.tabsMenu.destroy();
140 this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
141 this.tabsMenu = null;
143 this.tabsMenu = new Ext.menu.Menu();
144 this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
146 this.generateTabMenuItems();
148 var target = Ext.get(e.getTarget());
149 var xy = target.getXY();
151 //Y param + 24 pixels
154 this.tabsMenu.showAt(xy);
157 generateTabMenuItems : function() {
158 var curActive = this.getActiveTab();
159 var totalItems = this.items.getCount();
160 var pageSize = this.tabScrollerMenu.getPageSize();
163 if (totalItems > pageSize) {
164 var numSubMenus = Math.floor(totalItems / pageSize);
165 var remainder = totalItems % pageSize;
167 // Loop through all of the items and create submenus in chunks of 10
168 for (var i = 0 ; i < numSubMenus; i++) {
169 var curPage = (i + 1) * pageSize;
173 for (var x = 0; x < pageSize; x++) {
174 index = x + curPage - pageSize;
175 var item = this.items.get(index);
176 menuItems.push(this.autoGenMenuItem(item));
180 text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
187 var start = numSubMenus * pageSize;
189 for (var i = start ; i < totalItems; i ++ ) {
190 var item = this.items.get(i);
191 menuItems.push(this.autoGenMenuItem(item));
195 text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
202 this.items.each(function(item) {
203 if (item.id != curActive.id && !item.hidden) {
204 this.tabsMenu.add(this.autoGenMenuItem(item));
210 autoGenMenuItem : function(item) {
211 var maxText = this.tabScrollerMenu.getMaxText();
212 var text = Ext.util.Format.ellipsis(item.title, maxText);
216 handler : this.showTabFromMenu,
218 disabled : item.disabled,
220 iconCls : item.iconCls
225 showTabFromMenu : function(menuItem) {
226 this.setActiveTab(menuItem.tabToShow);
231 Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);