4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-boxOverflow-Menu'>/**
19 </span> * @class Ext.layout.container.boxOverflow.Menu
20 * @extends Ext.layout.container.boxOverflow.None
23 Ext.define('Ext.layout.container.boxOverflow.Menu', {
25 /* Begin Definitions */
27 extend: 'Ext.layout.container.boxOverflow.None',
28 requires: ['Ext.toolbar.Separator', 'Ext.button.Button'],
29 alternateClassName: 'Ext.layout.boxOverflow.Menu',
33 <span id='Ext-layout-container-boxOverflow-Menu-cfg-afterCtCls'> /**
34 </span> * @cfg {String} afterCtCls
35 * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
36 * which must always be present at the rightmost edge of the Container
39 <span id='Ext-layout-container-boxOverflow-Menu-property-noItemsMenuText'> /**
40 </span> * @property noItemsMenuText
42 * HTML fragment to render into the toolbar overflow menu if there are no items to display
44 noItemsMenuText : '<div class="' + Ext.baseCSSPrefix + 'toolbar-no-items">(None)</div>',
46 constructor: function(layout) {
49 me.callParent(arguments);
51 // Before layout, we need to re-show all items which we may have hidden due to a previous overflow.
52 layout.beforeLayout = Ext.Function.createInterceptor(layout.beforeLayout, this.clearOverflow, this);
54 me.afterCtCls = me.afterCtCls || Ext.baseCSSPrefix + 'box-menu-' + layout.parallelAfter;
55 <span id='Ext-layout-container-boxOverflow-Menu-property-menuItems'> /**
56 </span> * @property menuItems
58 * Array of all items that are currently hidden and should go into the dropdown menu
63 onRemove: function(comp){
64 Ext.Array.remove(this.menuItems, comp);
67 handleOverflow: function(calculations, targetSize) {
70 methodName = 'get' + layout.parallelPrefixCap,
72 posArgs = [null, null];
74 me.callParent(arguments);
75 this.createMenu(calculations, targetSize);
76 newSize[layout.perpendicularPrefix] = targetSize[layout.perpendicularPrefix];
77 newSize[layout.parallelPrefix] = targetSize[layout.parallelPrefix] - me.afterCt[methodName]();
79 // Center the menuTrigger button.
80 // TODO: Should we emulate align: 'middle' like this, or should we 'stretchmax' the menuTrigger?
81 posArgs[layout.perpendicularSizeIndex] = (calculations.meta.maxSize - me.menuTrigger['get' + layout.perpendicularPrefixCap]()) / 2;
82 me.menuTrigger.setPosition.apply(me.menuTrigger, posArgs);
84 return { targetSize: newSize };
87 <span id='Ext-layout-container-boxOverflow-Menu-method-clearOverflow'> /**
89 * Called by the layout, when it determines that there is no overflow.
90 * Also called as an interceptor to the layout's onLayout method to reshow
91 * previously hidden overflowing items.
93 clearOverflow: function(calculations, targetSize) {
95 newWidth = targetSize ? targetSize.width + (me.afterCt ? me.afterCt.getWidth() : 0) : 0,
98 length = items.length,
102 for (; i < length; i++) {
107 return targetSize ? {
109 height: targetSize.height,
115 <span id='Ext-layout-container-boxOverflow-Menu-method-showTrigger'> /**
118 showTrigger: function() {
119 this.menuTrigger.show();
122 <span id='Ext-layout-container-boxOverflow-Menu-method-hideTrigger'> /**
125 hideTrigger: function() {
126 if (this.menuTrigger !== undefined) {
127 this.menuTrigger.hide();
131 <span id='Ext-layout-container-boxOverflow-Menu-method-beforeMenuShow'> /**
133 * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
135 beforeMenuShow: function(menu) {
137 items = me.menuItems,
143 var needsSep = function(group, prev){
144 return group.isXType('buttongroup') && !(prev instanceof Ext.toolbar.Separator);
150 for (; i < len; i++) {
153 // Do not show a separator as a first item
154 if (!i && (item instanceof Ext.toolbar.Separator)) {
157 if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
161 me.addComponentToMenu(menu, item);
165 // put something so the menu isn't empty if no compatible items found
166 if (menu.items.length < 1) {
167 menu.add(me.noItemsMenuText);
171 <span id='Ext-layout-container-boxOverflow-Menu-method-createMenuConfig'> /**
173 * Returns a menu config for a given component. This config is used to create a menu item
174 * to be added to the expander menu
175 * @param {Ext.Component} component The component to create the config for
176 * @param {Boolean} hideOnClick Passed through to the menu item
178 createMenuConfig : function(component, hideOnClick) {
179 var config = Ext.apply({}, component.initialConfig),
180 group = component.toggleGroup;
182 Ext.copyTo(config, component, [
183 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
187 text : component.overflowText || component.text,
188 hideOnClick: hideOnClick,
192 if (group || component.enableToggle) {
195 checked: component.pressed,
197 checkchange: function(item, checked){
198 component.toggle(checked);
204 delete config.ownerCt;
210 <span id='Ext-layout-container-boxOverflow-Menu-method-addComponentToMenu'> /**
212 * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
213 * @param {Ext.menu.Menu} menu The menu to add to
214 * @param {Ext.Component} component The component to add
216 addComponentToMenu : function(menu, component) {
218 if (component instanceof Ext.toolbar.Separator) {
220 } else if (component.isComponent) {
221 if (component.isXType('splitbutton')) {
222 menu.add(me.createMenuConfig(component, true));
224 } else if (component.isXType('button')) {
225 menu.add(me.createMenuConfig(component, !component.menu));
227 } else if (component.isXType('buttongroup')) {
228 component.items.each(function(item){
229 me.addComponentToMenu(menu, item);
232 menu.add(Ext.create(Ext.getClassName(component), me.createMenuConfig(component)));
237 <span id='Ext-layout-container-boxOverflow-Menu-method-clearMenu'> /**
239 * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
240 * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
242 clearMenu : function() {
243 var menu = this.moreMenu;
244 if (menu && menu.items) {
245 menu.items.each(function(item) {
253 <span id='Ext-layout-container-boxOverflow-Menu-method-createMenu'> /**
255 * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
256 * in the layout are too wide to fit in the space available
258 createMenu: function(calculations, targetSize) {
261 startProp = layout.parallelBefore,
262 sizeProp = layout.parallelPrefix,
263 available = targetSize[sizeProp],
264 boxes = calculations.boxes,
269 if (!me.menuTrigger) {
270 me.createInnerElements();
272 <span id='Ext-layout-container-boxOverflow-Menu-property-menu'> /**
275 * @type Ext.menu.Menu
276 * The expand menu - holds items for every item that cannot be shown
277 * because the container is currently not large enough.
279 me.menu = Ext.create('Ext.menu.Menu', {
282 beforeshow: me.beforeMenuShow
286 <span id='Ext-layout-container-boxOverflow-Menu-property-menuTrigger'> /**
288 * @property menuTrigger
289 * @type Ext.button.Button
290 * The expand button which triggers the overflow menu to be shown
292 me.menuTrigger = Ext.create('Ext.button.Button', {
293 ownerCt : me.layout.owner, // To enable the Menu to ascertain a valid zIndexManager owner in the same tree
294 iconCls : Ext.baseCSSPrefix + layout.owner.getXType() + '-more-icon',
295 ui : layout.owner instanceof Ext.toolbar.Toolbar ? 'default-toolbar' : 'default',
297 getSplitCls: function() { return '';},
302 available -= me.afterCt.getWidth();
304 // Hide all items which are off the end, and store them to allow them to be restored
305 // before each layout operation.
306 me.menuItems.length = 0;
307 for (; i < len; i++) {
309 if (box[startProp] + box[sizeProp] > available) {
310 me.menuItems.push(box.component);
311 box.component.hide();
316 <span id='Ext-layout-container-boxOverflow-Menu-method-createInnerElements'> /**
318 * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
319 * @param {Ext.container.Container} container The Container attached to this Layout instance
320 * @param {Ext.core.Element} target The target Element
322 createInnerElements: function() {
324 target = me.layout.getRenderTarget();
327 target.addCls(Ext.baseCSSPrefix + me.layout.direction + '-box-overflow-body');
328 this.afterCt = target.insertSibling({cls: Ext.layout.container.Box.prototype.innerCls + ' ' + this.afterCtCls}, 'before');
332 <span id='Ext-layout-container-boxOverflow-Menu-method-destroy'> /**
335 destroy: function() {
336 Ext.destroy(this.menu, this.menuTrigger);