1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-menu.Item-method-constructor'><span id='Ext-menu.Item'>/**
2 </span></span> * @class Ext.menu.Item
3 * @extends Ext.Component
5 * A base class for all menu items that require menu-related functionality such as click handling,
6 * sub-menus, icons, etc.
7 * {@img Ext.menu.Menu/Ext.menu.Menu.png Ext.menu.Menu component}
9 Ext.create('Ext.menu.Menu', {
12 floating: false, // usually you want this set to True (default)
13 renderTo: Ext.getBody(), // usually rendered by it's containing component
28 * @param {Object} config The config object
30 Ext.define('Ext.menu.Item', {
31 extend: 'Ext.Component',
32 alias: 'widget.menuitem',
33 alternateClassName: 'Ext.menu.TextItem',
35 <span id='Ext-menu.Item-property-activated'> /**
36 </span> * @property {Boolean} activated
37 * Whether or not this item is currently activated
40 <span id='Ext-menu.Item-cfg-activeCls'> /**
41 </span> * @cfg {String} activeCls
42 * The CSS class added to the menu item when the item is activated (focused/mouseover).
43 * Defaults to `Ext.baseCSSPrefix + 'menu-item-active'`.
46 activeCls: Ext.baseCSSPrefix + 'menu-item-active',
48 <span id='Ext-menu.Item-cfg-ariaRole'> /**
49 </span> * @cfg {String} ariaRole @hide
53 <span id='Ext-menu.Item-cfg-canActivate'> /**
54 </span> * @cfg {Boolean} canActivate
55 * Whether or not this menu item can be activated when focused/mouseovered. Defaults to `true`.
60 <span id='Ext-menu.Item-cfg-clickHideDelay'> /**
61 </span> * @cfg {Number} clickHideDelay
62 * The delay in milliseconds to wait before hiding the menu after clicking the menu item.
63 * This only has an effect when `hideOnClick: true`. Defaults to `1`.
68 <span id='Ext-menu.Item-cfg-destroyMenu'> /**
69 </span> * @cfg {Boolean} destroyMenu
70 * Whether or not to destroy any associated sub-menu when this item is destroyed. Defaults to `true`.
74 <span id='Ext-menu.Item-cfg-disabledCls'> /**
75 </span> * @cfg {String} disabledCls
76 * The CSS class added to the menu item when the item is disabled.
77 * Defaults to `Ext.baseCSSPrefix + 'menu-item-disabled'`.
80 disabledCls: Ext.baseCSSPrefix + 'menu-item-disabled',
82 <span id='Ext-menu.Item-cfg-href'> /**
83 </span> * @cfg {String} href
84 * The href attribute to use for the underlying anchor link. Defaults to `#`.
88 <span id='Ext-menu.Item-cfg-hrefTarget'> /**
89 </span> * @cfg {String} hrefTarget
90 * The target attribute to use for the underlying anchor link. Defaults to `undefined`.
94 <span id='Ext-menu.Item-cfg-hideOnClick'> /**
95 </span> * @cfg {Boolean} hideOnClick
96 * Whether to not to hide the owning menu when this item is clicked. Defaults to `true`.
101 <span id='Ext-menu.Item-cfg-icon'> /**
102 </span> * @cfg {String} icon
103 * The path to an icon to display in this item. Defaults to `Ext.BLANK_IMAGE_URL`.
107 <span id='Ext-menu.Item-cfg-iconCls'> /**
108 </span> * @cfg {String} iconCls
109 * A CSS class that specifies a `background-image` to use as the icon for this item. Defaults to `undefined`.
115 <span id='Ext-menu.Item-property-menu'> /**
116 </span> * @cfg {Mixed} menu
117 * Either an instance of {@link Ext.menu.Menu} or a config object for an {@link Ext.menu.Menu}
118 * which will act as a sub-menu to this item.
120 * @property {Ext.menu.Menu} menu The sub-menu associated with this item, if one was configured.
123 <span id='Ext-menu.Item-cfg-menuAlign'> /**
124 </span> * @cfg {String} menuAlign
125 * The default {@link Ext.core.Element#getAlignToXY Ext.Element.getAlignToXY} anchor position value for this
126 * item's sub-menu relative to this item's position. Defaults to `'tl-tr?'`.
131 <span id='Ext-menu.Item-cfg-menuExpandDelay'> /**
132 </span> * @cfg {Number} menuExpandDelay
133 * The delay in milliseconds before this item's sub-menu expands after this item is moused over. Defaults to `200`.
136 menuExpandDelay: 200,
138 <span id='Ext-menu.Item-cfg-menuHideDelay'> /**
139 </span> * @cfg {Number} menuHideDelay
140 * The delay in milliseconds before this item's sub-menu hides after this item is moused out. Defaults to `200`.
145 <span id='Ext-menu.Item-cfg-plain'> /**
146 </span> * @cfg {Boolean} plain
147 * Whether or not this item is plain text/html with no icon or visual activation. Defaults to `false`.
152 '<tpl if="plain">',
155 '<tpl if="!plain">',
156 '<a class="' + Ext.baseCSSPrefix + 'menu-item-link" href="{href}" <tpl if="hrefTarget">target="{hrefTarget}"</tpl> hidefocus="true" unselectable="on">',
157 '<img src="{icon}" class="' + Ext.baseCSSPrefix + 'menu-item-icon {iconCls}" />',
158 '<span class="' + Ext.baseCSSPrefix + 'menu-item-text" <tpl if="menu">style="margin-right: 17px;"</tpl> >{text}</span>',
159 '<tpl if="menu">',
160 '<img src="' + Ext.BLANK_IMAGE_URL + '" class="' + Ext.baseCSSPrefix + 'menu-item-arrow" />',
166 maskOnDisable: false,
168 <span id='Ext-menu.Item-cfg-text'> /**
169 </span> * @cfg {String} text
170 * The text/html to display in this item. Defaults to `undefined`.
174 activate: function() {
177 if (!me.activated && me.canActivate && me.rendered && !me.isDisabled() && me.isVisible()) {
178 me.el.addCls(me.activeCls);
181 me.fireEvent('activate', me);
186 this.$focused = false;
187 this.callParent(arguments);
190 deactivate: function() {
194 me.el.removeCls(me.activeCls);
197 me.activated = false;
198 me.fireEvent('deactivate', me);
202 deferExpandMenu: function() {
205 if (!me.menu.rendered || !me.menu.isVisible()) {
206 me.parentMenu.activeChild = me.menu;
207 me.menu.parentItem = me;
208 me.menu.parentMenu = me.menu.ownerCt = me.parentMenu;
209 me.menu.showBy(me, me.menuAlign);
213 deferHideMenu: function() {
214 if (this.menu.isVisible()) {
219 deferHideParentMenus: function() {
220 Ext.menu.Manager.hideAll();
223 expandMenu: function(delay) {
227 clearTimeout(me.hideMenuTimer);
229 me.deferExpandMenu();
231 me.expandMenuTimer = Ext.defer(me.deferExpandMenu, Ext.isNumber(delay) ? delay : me.menuExpandDelay, me);
237 this.$focused = true;
238 this.callParent(arguments);
241 getRefItems: function(deep){
242 var menu = this.menu,
246 items = menu.getRefItems(deep);
252 hideMenu: function(delay) {
256 clearTimeout(me.expandMenuTimer);
257 me.hideMenuTimer = Ext.defer(me.deferHideMenu, Ext.isNumber(delay) ? delay : me.menuHideDelay, me);
261 initComponent: function() {
263 prefix = Ext.baseCSSPrefix,
264 cls = [prefix + 'menu-item'];
267 <span id='Ext-menu.Item-event-activate'> /**
268 </span> * @event activate
269 * Fires when this item is activated
270 * @param {Ext.menu.Item} item The activated item
274 <span id='Ext-menu.Item-event-click'> /**
275 </span> * @event click
276 * Fires when this item is clicked
277 * @param {Ext.menu.Item} item The item that was clicked
278 * @param {Ext.EventObject} e The underyling {@link Ext.EventObject}.
282 <span id='Ext-menu.Item-event-deactivate'> /**
283 </span> * @event deactivate
284 * Fires when this tiem is deactivated
285 * @param {Ext.menu.Item} item The deactivated item
291 cls.push(prefix + 'menu-item-plain');
298 me.cls = cls.join(' ');
301 me.menu = Ext.menu.Manager.get(me.menu);
304 me.callParent(arguments);
307 onClick: function(e) {
318 if (me.hideOnClick) {
319 me.deferHideParentMenusTimer = Ext.defer(me.deferHideParentMenus, me.clickHideDelay, me);
322 Ext.callback(me.handler, me.scope || me, [me, e]);
323 me.fireEvent('click', me, e);
325 if (!me.hideOnClick) {
330 onDestroy: function() {
333 clearTimeout(me.expandMenuTimer);
334 clearTimeout(me.hideMenuTimer);
335 clearTimeout(me.deferHideParentMenusTimer);
338 delete me.menu.parentItem;
339 delete me.menu.parentMenu;
340 delete me.menu.ownerCt;
341 if (me.destroyMenu !== false) {
345 me.callParent(arguments);
348 onRender: function(ct, pos) {
350 prefix = '.' + Ext.baseCSSPrefix;
352 Ext.applyIf(me.renderData, {
353 href: me.href || '#',
354 hrefTarget: me.hrefTarget,
355 icon: me.icon || Ext.BLANK_IMAGE_URL,
357 menu: Ext.isDefined(me.menu),
362 Ext.applyIf(me.renderSelectors, {
363 itemEl: prefix + 'menu-item-link',
364 iconEl: prefix + 'menu-item-icon',
365 textEl: prefix + 'menu-item-text',
366 arrowEl: prefix + 'menu-item-arrow'
369 me.callParent(arguments);
372 <span id='Ext-menu.Item-method-setHandler'> /**
373 </span> * Sets the {@link #click} handler of this item
374 * @param {Function} fn The handler function
375 * @param {Object} scope (optional) The scope of the handler function
377 setHandler: function(fn, scope) {
378 this.handler = fn || null;
382 <span id='Ext-menu.Item-method-setIconCls'> /**
383 </span> * Sets the {@link #iconCls} of this item
384 * @param {String} iconCls The CSS class to set to {@link #iconCls}
386 setIconCls: function(iconCls) {
391 me.iconEl.removeCls(me.iconCls);
395 me.iconEl.addCls(iconCls);
399 me.iconCls = iconCls;
402 <span id='Ext-menu.Item-method-setText'> /**
403 </span> * Sets the {@link #text} of this item
404 * @param {String} text The {@link #text}
406 setText: function(text) {
408 el = me.textEl || me.el,
411 if (text && el) {
415 // Resize the menu to fit the text
416 newWidth = me.textEl.getWidth() + me.iconEl.getWidth() + 25 + (me.arrowEl ? me.arrowEl.getWidth() : 0);
417 if (newWidth > me.itemEl.getWidth()) {
418 me.parentMenu.setWidth(newWidth);
428 </pre></pre></body></html>