1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
<div id="cls-Ext.layout.boxOverflow.Menu"></div>/**
* @class Ext.layout.boxOverflow.Menu
* @extends Ext.layout.boxOverflow.None
* Description
*/
Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
<div id="cfg-Ext.layout.boxOverflow.Menu-null"></div>/**
* @cfg afterCls
* @type String
* CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
* which must always be present at the rightmost edge of the Container
*/
afterCls: 'x-strip-right',
<div id="prop-Ext.layout.boxOverflow.Menu-noItemsMenuText"></div>/**
* @property noItemsMenuText
* @type String
* HTML fragment to render into the toolbar overflow menu if there are no items to display
*/
noItemsMenuText : '<div class="x-toolbar-no-items">(None)</div>',
constructor: function(layout) {
Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
<div id="prop-Ext.layout.boxOverflow.Menu-menuItems"></div>/**
* @property menuItems
* @type Array
* Array of all items that are currently hidden and should go into the dropdown menu
*/
this.menuItems = [];
},
/**
* @private
* Creates the beforeCt, innerCt and afterCt elements if they have not already been created
* @param {Ext.Container} container The Container attached to this Layout instance
* @param {Ext.Element} target The target Element
*/
createInnerElements: function() {
if (!this.afterCt) {
this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
}
},
/**
* @private
*/
clearOverflow: function(calculations, targetSize) {
var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
items = this.menuItems;
this.hideTrigger();
for (var index = 0, length = items.length; index < length; index++) {
items.pop().component.show();
}
return {
targetSize: {
height: targetSize.height,
width : newWidth
}
};
},
/**
* @private
*/
showTrigger: function() {
this.createMenu();
this.menuTrigger.show();
},
/**
* @private
*/
hideTrigger: function() {
if (this.menuTrigger != undefined) {
this.menuTrigger.hide();
}
},
/**
* @private
* Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
*/
beforeMenuShow: function(menu) {
var items = this.menuItems,
len = items.length,
item,
prev;
var needsSep = function(group, item){
return group.isXType('buttongroup') && !(item instanceof Ext.Toolbar.Separator);
};
this.clearMenu();
menu.removeAll();
for (var i = 0; i < len; i++) {
item = items[i].component;
if (prev && (needsSep(item, prev) || needsSep(prev, item))) {
menu.add('-');
}
this.addComponentToMenu(menu, item);
prev = item;
}
// put something so the menu isn't empty if no compatible items found
if (menu.items.length < 1) {
menu.add(this.noItemsMenuText);
}
},
/**
* @private
* Returns a menu config for a given component. This config is used to create a menu item
* to be added to the expander menu
* @param {Ext.Component} component The component to create the config for
* @param {Boolean} hideOnClick Passed through to the menu item
*/
createMenuConfig : function(component, hideOnClick){
var config = Ext.apply({}, component.initialConfig),
group = component.toggleGroup;
Ext.copyTo(config, component, [
'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
]);
Ext.apply(config, {
text : component.overflowText || component.text,
hideOnClick: hideOnClick
});
if (group || component.enableToggle) {
Ext.apply(config, {
group : group,
checked: component.pressed,
listeners: {
checkchange: function(item, checked){
component.toggle(checked);
}
}
});
}
delete config.ownerCt;
delete config.xtype;
delete config.id;
return config;
},
/**
* @private
* Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
* @param {Ext.menu.Menu} menu The menu to add to
* @param {Ext.Component} component The component to add
*/
addComponentToMenu : function(menu, component) {
if (component instanceof Ext.Toolbar.Separator) {
menu.add('-');
} else if (Ext.isFunction(component.isXType)) {
if (component.isXType('splitbutton')) {
menu.add(this.createMenuConfig(component, true));
} else if (component.isXType('button')) {
menu.add(this.createMenuConfig(component, !component.menu));
} else if (component.isXType('buttongroup')) {
component.items.each(function(item){
this.addComponentToMenu(menu, item);
}, this);
}
}
},
/**
* @private
* Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
* splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
*/
clearMenu : function(){
var menu = this.moreMenu;
if (menu && menu.items) {
menu.items.each(function(item){
delete item.menu;
});
}
},
/**
* @private
* Creates the overflow trigger and menu used when enableOverflow is set to true and the items
* in the layout are too wide to fit in the space available
*/
createMenu: function() {
if (!this.menuTrigger) {
this.createInnerElements();
/**
* @private
* @property menu
* @type Ext.menu.Menu
* The expand menu - holds items for every item that cannot be shown
* because the container is currently not large enough.
*/
this.menu = new Ext.menu.Menu({
ownerCt : this.layout.container,
listeners: {
scope: this,
beforeshow: this.beforeMenuShow
}
});
/**
* @private
* @property menuTrigger
* @type Ext.Button
* The expand button which triggers the overflow menu to be shown
*/
this.menuTrigger = new Ext.Button({
iconCls : 'x-toolbar-more-icon',
cls : 'x-toolbar-more',
menu : this.menu,
renderTo: this.afterCt
});
}
},
/**
* @private
*/
destroy: function() {
Ext.destroy(this.menu, this.menuTrigger);
}
});
Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
<div id="cls-Ext.layout.boxOverflow.HorizontalMenu"></div>/**
* @class Ext.layout.boxOverflow.HorizontalMenu
* @extends Ext.layout.boxOverflow.Menu
* Description
*/
Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
constructor: function() {
Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
var me = this,
layout = me.layout,
origFunction = layout.calculateChildBoxes;
layout.calculateChildBoxes = function(visibleItems, targetSize) {
var calcs = origFunction.apply(layout, arguments),
meta = calcs.meta,
items = me.menuItems;
//calculate the width of the items currently hidden solely because there is not enough space
//to display them
var hiddenWidth = 0;
for (var index = 0, length = items.length; index < length; index++) {
hiddenWidth += items[index].width;
}
meta.minimumWidth += hiddenWidth;
meta.tooNarrow = meta.minimumWidth > targetSize.width;
return calcs;
};
},
handleOverflow: function(calculations, targetSize) {
this.showTrigger();
var newWidth = targetSize.width - this.afterCt.getWidth(),
boxes = calculations.boxes,
usedWidth = 0,
recalculate = false;
//calculate the width of all visible items and any spare width
for (var index = 0, length = boxes.length; index < length; index++) {
usedWidth += boxes[index].width;
}
var spareWidth = newWidth - usedWidth,
showCount = 0;
//see if we can re-show any of the hidden components
for (var index = 0, length = this.menuItems.length; index < length; index++) {
var hidden = this.menuItems[index],
comp = hidden.component,
width = hidden.width;
if (width < spareWidth) {
comp.show();
spareWidth -= width;
showCount ++;
recalculate = true;
} else {
break;
}
}
if (recalculate) {
this.menuItems = this.menuItems.slice(showCount);
} else {
for (var i = boxes.length - 1; i >= 0; i--) {
var item = boxes[i].component,
right = boxes[i].left + boxes[i].width;
if (right >= newWidth) {
this.menuItems.unshift({
component: item,
width : boxes[i].width
});
item.hide();
} else {
break;
}
}
}
if (this.menuItems.length == 0) {
this.hideTrigger();
}
return {
targetSize: {
height: targetSize.height,
width : newWidth
},
recalculate: recalculate
};
}
});
Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;</pre>
</body>
</html>
|