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.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.layout.MenuLayout"></div>/**
16 * @class Ext.layout.MenuLayout
17 * @extends Ext.layout.ContainerLayout
18 * <p>Layout manager used by {@link Ext.menu.Menu}. Generally this class should not need to be used directly.</p>
20 Ext.layout.MenuLayout = Ext.extend(Ext.layout.ContainerLayout, {
25 setContainer : function(ct){
26 this.monitorResize = !ct.floating;
27 // This event is only fired by the menu in IE, used so we don't couple
28 // the menu with the layout.
29 ct.on('autosize', this.doAutoSize, this);
30 Ext.layout.MenuLayout.superclass.setContainer.call(this, ct);
33 renderItem : function(c, position, target){
35 this.itemTpl = Ext.layout.MenuLayout.prototype.itemTpl = new Ext.XTemplate(
36 '<li id="{itemId}" class="{itemCls}">',
37 '<tpl if="needsIcon">',
38 '<img src="{icon}" class="{iconCls}"/>',
45 if(Ext.isNumber(position)){
46 position = target.dom.childNodes[position];
48 var a = this.getItemArgs(c);
50 // The Component's positionEl is the <li> it is rendered into
51 c.render(c.positionEl = position ?
52 this.itemTpl.insertBefore(position, a, true) :
53 this.itemTpl.append(target, a, true));
55 // Link the containing <li> to the item.
56 c.positionEl.menuItemId = c.getItemId();
58 // If rendering a regular Component, and it needs an icon,
59 // move the Component rightwards.
60 if (!a.isMenuItem && a.needsIcon) {
61 c.positionEl.addClass('x-menu-list-item-indent');
63 this.configureItem(c, position);
64 }else if(c && !this.isValidParent(c, target)){
65 if(Ext.isNumber(position)){
66 position = target.dom.childNodes[position];
68 target.dom.insertBefore(c.getActionEl().dom, position || null);
72 getItemArgs : function(c) {
73 var isMenuItem = c instanceof Ext.menu.Item;
75 isMenuItem: isMenuItem,
76 needsIcon: !isMenuItem && (c.icon || c.iconCls),
77 icon: c.icon || Ext.BLANK_IMAGE_URL,
78 iconCls: 'x-menu-item-icon ' + (c.iconCls || ''),
79 itemId: 'x-menu-el-' + c.id,
80 itemCls: 'x-menu-list-item '
84 // Valid if the Component is in a <li> which is part of our target <ul>
85 isValidParent : function(c, target) {
86 return c.el.up('li.x-menu-list-item', 5).dom.parentNode === (target.dom || target);
89 onLayout : function(ct, target){
90 Ext.layout.MenuLayout.superclass.onLayout.call(this, ct, target);
94 doAutoSize : function(){
95 var ct = this.container, w = ct.width;
100 ct.setWidth(Ext.isStrict && (Ext.isIE7 || Ext.isIE8) ? 'auto' : ct.minWidth);
101 var el = ct.getEl(), t = el.dom.offsetWidth; // force recalc
102 ct.setWidth(ct.getLayoutTarget().getWidth() + el.getFrameWidth('lr'));
107 Ext.Container.LAYOUTS['menu'] = Ext.layout.MenuLayout;