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
15 <div id="cls-Ext.layout.boxOverflow.Menu"></div>/**
16 * @class Ext.layout.boxOverflow.Menu
17 * @extends Ext.layout.boxOverflow.None
20 Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
21 <div id="cfg-Ext.layout.boxOverflow.Menu-null"></div>/**
24 * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
25 * which must always be present at the rightmost edge of the Container
27 afterCls: 'x-strip-right',
29 <div id="prop-Ext.layout.boxOverflow.Menu-noItemsMenuText"></div>/**
30 * @property noItemsMenuText
32 * HTML fragment to render into the toolbar overflow menu if there are no items to display
34 noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
36 constructor: function(layout) {
37 Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
39 <div id="prop-Ext.layout.boxOverflow.Menu-menuItems"></div>/**
42 * Array of all items that are currently hidden and should go into the dropdown menu
49 * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
50 * @param {Ext.Container} container The Container attached to this Layout instance
51 * @param {Ext.Element} target The target Element
53 createInnerElements: function() {
55 this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
62 clearOverflow: function(calculations, targetSize) {
63 var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
64 items = this.menuItems;
68 for (var index = 0, length = items.length; index < length; index++) {
69 items.pop().component.show();
74 height: targetSize.height,
83 showTrigger: function() {
85 this.menuTrigger.show();
91 hideTrigger: function() {
92 if (this.menuTrigger != undefined) {
93 this.menuTrigger.hide();
99 * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
101 beforeMenuShow: function(menu) {
102 var items = this.menuItems,
107 var needsSep = function(group, item){
108 return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
114 for (var i = 0; i < len; i++) {
115 item = items[i].component;
117 if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
121 this.addComponentToMenu(menu, item);
125 // put something so the menu isn't empty if no compatible items found
126 if (menu.items.length < 1) {
127 menu.add(this.noItemsMenuText);
133 * Returns a menu config for a given component. This config is used to create a menu item
134 * to be added to the expander menu
135 * @param {Ext.Component} component The component to create the config for
136 * @param {Boolean} hideOnClick Passed through to the menu item
138 createMenuConfig : function(component, hideOnClick){
139 var config = Ext.apply({}, component.initialConfig),
140 group = component.toggleGroup;
142 Ext.copyTo(config, component, [
143 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
147 text : component.overflowText || component.text,
148 hideOnClick: hideOnClick
151 if (group || component.enableToggle) {
154 checked: component.pressed,
156 checkchange: function(item, checked){
157 component.toggle(checked);
163 delete config.ownerCt;
172 * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
173 * @param {Ext.menu.Menu} menu The menu to add to
174 * @param {Ext.Component} component The component to add
176 addComponentToMenu : function(menu, component) {
177 if (component instanceof Ext.Toolbar.Separator) {
180 } else if (Ext.isFunction(component.isXType)) {
181 if (component.isXType('splitbutton')) {
182 menu.add(this.createMenuConfig(component, true));
184 } else if (component.isXType('button')) {
185 menu.add(this.createMenuConfig(component, !component.menu));
187 } else if (component.isXType('buttongroup')) {
188 component.items.each(function(item){
189 this.addComponentToMenu(menu, item);
197 * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
198 * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
200 clearMenu : function(){
201 var menu = this.moreMenu;
202 if (menu && menu.items) {
203 menu.items.each(function(item){
211 * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
212 * in the layout are too wide to fit in the space available
214 createMenu: function() {
215 if (!this.menuTrigger) {
216 this.createInnerElements();
221 * @type Ext.menu.Menu
222 * The expand menu - holds items for every item that cannot be shown
223 * because the container is currently not large enough.
225 this.menu = new Ext.menu.Menu({
226 ownerCt : this.layout.container,
229 beforeshow: this.beforeMenuShow
235 * @property menuTrigger
237 * The expand button which triggers the overflow menu to be shown
239 this.menuTrigger = new Ext.Button({
240 iconCls : 'x-toolbar-more-icon',
241 cls : 'x-toolbar-more',
243 renderTo: this.afterCt
251 destroy: function() {
252 Ext.destroy(this.menu, this.menuTrigger);
256 Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
259 <div id="cls-Ext.layout.boxOverflow.HorizontalMenu"></div>/**
260 * @class Ext.layout.boxOverflow.HorizontalMenu
261 * @extends Ext.layout.boxOverflow.Menu
264 Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
266 constructor: function() {
267 Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
271 origFunction = layout.calculateChildBoxes;
273 layout.calculateChildBoxes = function(visibleItems, targetSize) {
274 var calcs = origFunction.apply(layout, arguments),
276 items = me.menuItems;
278 //calculate the width of the items currently hidden solely because there is not enough space
281 for (var index = 0, length = items.length; index < length; index++) {
282 hiddenWidth += items[index].width;
285 meta.minimumWidth += hiddenWidth;
286 meta.tooNarrow = meta.minimumWidth > targetSize.width;
292 handleOverflow: function(calculations, targetSize) {
295 var newWidth = targetSize.width - this.afterCt.getWidth(),
296 boxes = calculations.boxes,
300 //calculate the width of all visible items and any spare width
301 for (var index = 0, length = boxes.length; index < length; index++) {
302 usedWidth += boxes[index].width;
305 var spareWidth = newWidth - usedWidth,
308 //see if we can re-show any of the hidden components
309 for (var index = 0, length = this.menuItems.length; index < length; index++) {
310 var hidden = this.menuItems[index],
311 comp = hidden.component,
312 width = hidden.width;
314 if (width < spareWidth) {
326 this.menuItems = this.menuItems.slice(showCount);
328 for (var i = boxes.length - 1; i >= 0; i--) {
329 var item = boxes[i].component,
330 right = boxes[i].left + boxes[i].width;
332 if (right >= newWidth) {
333 this.menuItems.unshift({
335 width : boxes[i].width
345 if (this.menuItems.length == 0) {
351 height: targetSize.height,
354 recalculate: recalculate
359 Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;</pre>