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.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 alt="{altText}" 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);
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,
74 canHaveIcon = !(isMenuItem || c instanceof Ext.menu.Separator);
77 isMenuItem: isMenuItem,
78 needsIcon: canHaveIcon && (c.icon || c.iconCls),
79 icon: c.icon || Ext.BLANK_IMAGE_URL,
80 iconCls: 'x-menu-item-icon ' + (c.iconCls || ''),
81 itemId: 'x-menu-el-' + c.id,
82 itemCls: 'x-menu-list-item ',
83 altText: c.altText || ''
87 // Valid if the Component is in a <li> which is part of our target <ul>
88 isValidParent : function(c, target) {
89 return c.el.up('li.x-menu-list-item', 5).dom.parentNode === (target.dom || target);
92 onLayout : function(ct, target){
93 Ext.layout.MenuLayout.superclass.onLayout.call(this, ct, target);
97 doAutoSize : function(){
98 var ct = this.container, w = ct.width;
103 ct.setWidth(Ext.isStrict && (Ext.isIE7 || Ext.isIE8) ? 'auto' : ct.minWidth);
104 var el = ct.getEl(), t = el.dom.offsetWidth; // force recalc
105 ct.setWidth(ct.getLayoutTarget().getWidth() + el.getFrameWidth('lr'));
110 Ext.Container.LAYOUTS['menu'] = Ext.layout.MenuLayout;