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-menu-Item'>/**
19 </span> * @class Ext.menu.Item
20 * @extends Ext.Component
22 * A base class for all menu items that require menu-related functionality such as click handling,
23 * sub-menus, icons, etc.
25 * {@img Ext.menu.Menu/Ext.menu.Menu.png Ext.menu.Menu component}
29 * Ext.create('Ext.menu.Menu', {
32 * floating: false, // usually you want this set to True (default)
33 * renderTo: Ext.getBody(), // usually rendered by it's containing component
46 Ext.define('Ext.menu.Item', {
47 extend: 'Ext.Component',
48 alias: 'widget.menuitem',
49 alternateClassName: 'Ext.menu.TextItem',
51 <span id='Ext-menu-Item-property-activated'> /**
52 </span> * @property {Boolean} activated
53 * Whether or not this item is currently activated
56 <span id='Ext-menu-Item-cfg-activeCls'> /**
57 </span> * @cfg {String} activeCls
58 * The CSS class added to the menu item when the item is activated (focused/mouseover).
59 * Defaults to `Ext.baseCSSPrefix + 'menu-item-active'`.
62 activeCls: Ext.baseCSSPrefix + 'menu-item-active',
64 <span id='Ext-menu-Item-cfg-ariaRole'> /**
65 </span> * @cfg {String} ariaRole @hide
69 <span id='Ext-menu-Item-cfg-canActivate'> /**
70 </span> * @cfg {Boolean} canActivate
71 * Whether or not this menu item can be activated when focused/mouseovered. Defaults to `true`.
76 <span id='Ext-menu-Item-cfg-clickHideDelay'> /**
77 </span> * @cfg {Number} clickHideDelay
78 * The delay in milliseconds to wait before hiding the menu after clicking the menu item.
79 * This only has an effect when `hideOnClick: true`. Defaults to `1`.
84 <span id='Ext-menu-Item-cfg-destroyMenu'> /**
85 </span> * @cfg {Boolean} destroyMenu
86 * Whether or not to destroy any associated sub-menu when this item is destroyed. Defaults to `true`.
90 <span id='Ext-menu-Item-cfg-disabledCls'> /**
91 </span> * @cfg {String} disabledCls
92 * The CSS class added to the menu item when the item is disabled.
93 * Defaults to `Ext.baseCSSPrefix + 'menu-item-disabled'`.
96 disabledCls: Ext.baseCSSPrefix + 'menu-item-disabled',
98 <span id='Ext-menu-Item-cfg-href'> /**
99 </span> * @cfg {String} href
100 * The href attribute to use for the underlying anchor link. Defaults to `#`.
104 <span id='Ext-menu-Item-cfg-hrefTarget'> /**
105 </span> * @cfg {String} hrefTarget
106 * The target attribute to use for the underlying anchor link. Defaults to `undefined`.
110 <span id='Ext-menu-Item-cfg-hideOnClick'> /**
111 </span> * @cfg {Boolean} hideOnClick
112 * Whether to not to hide the owning menu when this item is clicked. Defaults to `true`.
117 <span id='Ext-menu-Item-cfg-icon'> /**
118 </span> * @cfg {String} icon
119 * The path to an icon to display in this item. Defaults to `Ext.BLANK_IMAGE_URL`.
123 <span id='Ext-menu-Item-cfg-iconCls'> /**
124 </span> * @cfg {String} iconCls
125 * A CSS class that specifies a `background-image` to use as the icon for this item. Defaults to `undefined`.
131 <span id='Ext-menu-Item-property-menu'> /**
132 </span> * @cfg {Mixed} menu
133 * Either an instance of {@link Ext.menu.Menu} or a config object for an {@link Ext.menu.Menu}
134 * which will act as a sub-menu to this item.
136 * @property {Ext.menu.Menu} menu The sub-menu associated with this item, if one was configured.
139 <span id='Ext-menu-Item-cfg-menuAlign'> /**
140 </span> * @cfg {String} menuAlign
141 * The default {@link Ext.core.Element#getAlignToXY Ext.Element.getAlignToXY} anchor position value for this
142 * item's sub-menu relative to this item's position. Defaults to `'tl-tr?'`.
147 <span id='Ext-menu-Item-cfg-menuExpandDelay'> /**
148 </span> * @cfg {Number} menuExpandDelay
149 * The delay in milliseconds before this item's sub-menu expands after this item is moused over. Defaults to `200`.
152 menuExpandDelay: 200,
154 <span id='Ext-menu-Item-cfg-menuHideDelay'> /**
155 </span> * @cfg {Number} menuHideDelay
156 * The delay in milliseconds before this item's sub-menu hides after this item is moused out. Defaults to `200`.
161 <span id='Ext-menu-Item-cfg-plain'> /**
162 </span> * @cfg {Boolean} plain
163 * Whether or not this item is plain text/html with no icon or visual activation. Defaults to `false`.
168 '<tpl if="plain">',
171 '<tpl if="!plain">',
172 '<a class="' + Ext.baseCSSPrefix + 'menu-item-link" href="{href}" <tpl if="hrefTarget">target="{hrefTarget}"</tpl> hidefocus="true" unselectable="on">',
173 '<img src="{icon}" class="' + Ext.baseCSSPrefix + 'menu-item-icon {iconCls}" />',
174 '<span class="' + Ext.baseCSSPrefix + 'menu-item-text" <tpl if="menu">style="margin-right: 17px;"</tpl> >{text}</span>',
175 '<tpl if="menu">',
176 '<img src="' + Ext.BLANK_IMAGE_URL + '" class="' + Ext.baseCSSPrefix + 'menu-item-arrow" />',
182 maskOnDisable: false,
184 <span id='Ext-menu-Item-cfg-text'> /**
185 </span> * @cfg {String} text
186 * The text/html to display in this item. Defaults to `undefined`.
190 activate: function() {
193 if (!me.activated && me.canActivate && me.rendered && !me.isDisabled() && me.isVisible()) {
194 me.el.addCls(me.activeCls);
197 me.fireEvent('activate', me);
202 this.$focused = false;
203 this.callParent(arguments);
206 deactivate: function() {
210 me.el.removeCls(me.activeCls);
213 me.activated = false;
214 me.fireEvent('deactivate', me);
218 deferExpandMenu: function() {
221 if (!me.menu.rendered || !me.menu.isVisible()) {
222 me.parentMenu.activeChild = me.menu;
223 me.menu.parentItem = me;
224 me.menu.parentMenu = me.menu.ownerCt = me.parentMenu;
225 me.menu.showBy(me, me.menuAlign);
229 deferHideMenu: function() {
230 if (this.menu.isVisible()) {
235 deferHideParentMenus: function() {
236 Ext.menu.Manager.hideAll();
239 expandMenu: function(delay) {
243 clearTimeout(me.hideMenuTimer);
245 me.deferExpandMenu();
247 me.expandMenuTimer = Ext.defer(me.deferExpandMenu, Ext.isNumber(delay) ? delay : me.menuExpandDelay, me);
253 this.$focused = true;
254 this.callParent(arguments);
257 getRefItems: function(deep){
258 var menu = this.menu,
262 items = menu.getRefItems(deep);
268 hideMenu: function(delay) {
272 clearTimeout(me.expandMenuTimer);
273 me.hideMenuTimer = Ext.defer(me.deferHideMenu, Ext.isNumber(delay) ? delay : me.menuHideDelay, me);
277 initComponent: function() {
279 prefix = Ext.baseCSSPrefix,
280 cls = [prefix + 'menu-item'];
283 <span id='Ext-menu-Item-event-activate'> /**
284 </span> * @event activate
285 * Fires when this item is activated
286 * @param {Ext.menu.Item} item The activated item
290 <span id='Ext-menu-Item-event-click'> /**
291 </span> * @event click
292 * Fires when this item is clicked
293 * @param {Ext.menu.Item} item The item that was clicked
294 * @param {Ext.EventObject} e The underyling {@link Ext.EventObject}.
298 <span id='Ext-menu-Item-event-deactivate'> /**
299 </span> * @event deactivate
300 * Fires when this tiem is deactivated
301 * @param {Ext.menu.Item} item The deactivated item
307 cls.push(prefix + 'menu-item-plain');
314 me.cls = cls.join(' ');
317 me.menu = Ext.menu.Manager.get(me.menu);
320 me.callParent(arguments);
323 onClick: function(e) {
334 if (me.hideOnClick) {
335 me.deferHideParentMenusTimer = Ext.defer(me.deferHideParentMenus, me.clickHideDelay, me);
338 Ext.callback(me.handler, me.scope || me, [me, e]);
339 me.fireEvent('click', me, e);
341 if (!me.hideOnClick) {
346 onDestroy: function() {
349 clearTimeout(me.expandMenuTimer);
350 clearTimeout(me.hideMenuTimer);
351 clearTimeout(me.deferHideParentMenusTimer);
354 delete me.menu.parentItem;
355 delete me.menu.parentMenu;
356 delete me.menu.ownerCt;
357 if (me.destroyMenu !== false) {
361 me.callParent(arguments);
364 onRender: function(ct, pos) {
366 prefix = '.' + Ext.baseCSSPrefix;
368 Ext.applyIf(me.renderData, {
369 href: me.href || '#',
370 hrefTarget: me.hrefTarget,
371 icon: me.icon || Ext.BLANK_IMAGE_URL,
372 iconCls: me.iconCls + (me.checkChangeDisabled ? ' ' + me.disabledCls : ''),
373 menu: Ext.isDefined(me.menu),
378 Ext.applyIf(me.renderSelectors, {
379 itemEl: prefix + 'menu-item-link',
380 iconEl: prefix + 'menu-item-icon',
381 textEl: prefix + 'menu-item-text',
382 arrowEl: prefix + 'menu-item-arrow'
385 me.callParent(arguments);
388 <span id='Ext-menu-Item-method-setHandler'> /**
389 </span> * Sets the {@link #click} handler of this item
390 * @param {Function} fn The handler function
391 * @param {Object} scope (optional) The scope of the handler function
393 setHandler: function(fn, scope) {
394 this.handler = fn || null;
398 <span id='Ext-menu-Item-method-setIconCls'> /**
399 </span> * Sets the {@link #iconCls} of this item
400 * @param {String} iconCls The CSS class to set to {@link #iconCls}
402 setIconCls: function(iconCls) {
407 me.iconEl.removeCls(me.iconCls);
411 me.iconEl.addCls(iconCls);
415 me.iconCls = iconCls;
418 <span id='Ext-menu-Item-method-setText'> /**
419 </span> * Sets the {@link #text} of this item
420 * @param {String} text The {@link #text}
422 setText: function(text) {
424 el = me.textEl || me.el;
429 el.update(text || '');
430 // cannot just call doComponentLayout due to stretchmax
431 me.ownerCt.redoComponentLayout();