4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * A base class for all menu items that require menu-related functionality such as click handling,
20 * sub-menus, icons, etc.
23 * Ext.create('Ext.menu.Menu', {
26 * floating: false, // usually you want this set to True (default)
27 * renderTo: Ext.getBody(), // usually rendered by it's containing component
39 Ext.define('Ext.menu.Item', {
40 extend: 'Ext.Component',
41 alias: 'widget.menuitem',
42 alternateClassName: 'Ext.menu.TextItem',
44 <span id='Ext-menu-Item-property-activated'> /**
45 </span> * @property {Boolean} activated
46 * Whether or not this item is currently activated
49 <span id='Ext-menu-Item-property-parentMenu'> /**
50 </span> * @property {Ext.menu.Menu} parentMenu
51 * The parent Menu of this item.
54 <span id='Ext-menu-Item-cfg-activeCls'> /**
55 </span> * @cfg {String} activeCls
56 * The CSS class added to the menu item when the item is activated (focused/mouseover).
57 * Defaults to `Ext.baseCSSPrefix + 'menu-item-active'`.
59 activeCls: Ext.baseCSSPrefix + 'menu-item-active',
61 <span id='Ext-menu-Item-cfg-ariaRole'> /**
62 </span> * @cfg {String} ariaRole @hide
66 <span id='Ext-menu-Item-cfg-canActivate'> /**
67 </span> * @cfg {Boolean} canActivate
68 * Whether or not this menu item can be activated when focused/mouseovered. Defaults to `true`.
72 <span id='Ext-menu-Item-cfg-clickHideDelay'> /**
73 </span> * @cfg {Number} clickHideDelay
74 * The delay in milliseconds to wait before hiding the menu after clicking the menu item.
75 * This only has an effect when `hideOnClick: true`. Defaults to `1`.
79 <span id='Ext-menu-Item-cfg-destroyMenu'> /**
80 </span> * @cfg {Boolean} destroyMenu
81 * Whether or not to destroy any associated sub-menu when this item is destroyed. Defaults to `true`.
85 <span id='Ext-menu-Item-cfg-disabledCls'> /**
86 </span> * @cfg {String} disabledCls
87 * The CSS class added to the menu item when the item is disabled.
88 * Defaults to `Ext.baseCSSPrefix + 'menu-item-disabled'`.
90 disabledCls: Ext.baseCSSPrefix + 'menu-item-disabled',
92 <span id='Ext-menu-Item-cfg-href'> /**
93 </span> * @cfg {String} href
94 * The href attribute to use for the underlying anchor link. Defaults to `#`.
98 <span id='Ext-menu-Item-cfg-hrefTarget'> /**
99 </span> * @cfg {String} hrefTarget
100 * The target attribute to use for the underlying anchor link. Defaults to `undefined`.
104 <span id='Ext-menu-Item-cfg-hideOnClick'> /**
105 </span> * @cfg {Boolean} hideOnClick
106 * Whether to not to hide the owning menu when this item is clicked. Defaults to `true`.
111 <span id='Ext-menu-Item-cfg-icon'> /**
112 </span> * @cfg {String} icon
113 * The path to an icon to display in this item. Defaults to `Ext.BLANK_IMAGE_URL`.
117 <span id='Ext-menu-Item-cfg-iconCls'> /**
118 </span> * @cfg {String} iconCls
119 * A CSS class that specifies a `background-image` to use as the icon for this item. Defaults to `undefined`.
125 <span id='Ext-menu-Item-property-menu'> /**
126 </span> * @cfg {Mixed} menu
127 * Either an instance of {@link Ext.menu.Menu} or a config object for an {@link Ext.menu.Menu}
128 * which will act as a sub-menu to this item.
130 * @property {Ext.menu.Menu} menu The sub-menu associated with this item, if one was configured.
133 <span id='Ext-menu-Item-cfg-menuAlign'> /**
134 </span> * @cfg {String} menuAlign
135 * The default {@link Ext.Element#getAlignToXY Ext.Element.getAlignToXY} anchor position value for this
136 * item's sub-menu relative to this item's position. Defaults to `'tl-tr?'`.
141 <span id='Ext-menu-Item-cfg-menuExpandDelay'> /**
142 </span> * @cfg {Number} menuExpandDelay
143 * The delay in milliseconds before this item's sub-menu expands after this item is moused over. Defaults to `200`.
146 menuExpandDelay: 200,
148 <span id='Ext-menu-Item-cfg-menuHideDelay'> /**
149 </span> * @cfg {Number} menuHideDelay
150 * The delay in milliseconds before this item's sub-menu hides after this item is moused out. Defaults to `200`.
155 <span id='Ext-menu-Item-cfg-plain'> /**
156 </span> * @cfg {Boolean} plain
157 * Whether or not this item is plain text/html with no icon or visual activation. Defaults to `false`.
162 '<tpl if="plain">',
165 '<tpl if="!plain">',
166 '<a id="{id}-itemEl" class="' + Ext.baseCSSPrefix + 'menu-item-link" href="{href}" <tpl if="hrefTarget">target="{hrefTarget}"</tpl> hidefocus="true" unselectable="on">',
167 '<img id="{id}-iconEl" src="{icon}" class="' + Ext.baseCSSPrefix + 'menu-item-icon {iconCls}" />',
168 '<span id="{id}-textEl" class="' + Ext.baseCSSPrefix + 'menu-item-text" <tpl if="menu">style="margin-right: 17px;"</tpl> >{text}</span>',
169 '<tpl if="menu">',
170 '<img id="{id}-arrowEl" src="{blank}" class="' + Ext.baseCSSPrefix + 'menu-item-arrow" />',
176 maskOnDisable: false,
178 <span id='Ext-menu-Item-cfg-text'> /**
179 </span> * @cfg {String} text
180 * The text/html to display in this item. Defaults to `undefined`.
184 activate: function() {
187 if (!me.activated && me.canActivate && me.rendered && !me.isDisabled() && me.isVisible()) {
188 me.el.addCls(me.activeCls);
191 me.fireEvent('activate', me);
196 this.$focused = false;
197 this.callParent(arguments);
200 deactivate: function() {
204 me.el.removeCls(me.activeCls);
207 me.activated = false;
208 me.fireEvent('deactivate', me);
212 deferExpandMenu: function() {
215 if (!me.menu.rendered || !me.menu.isVisible()) {
216 me.parentMenu.activeChild = me.menu;
217 me.menu.parentItem = me;
218 me.menu.parentMenu = me.menu.ownerCt = me.parentMenu;
219 me.menu.showBy(me, me.menuAlign);
223 deferHideMenu: function() {
224 if (this.menu.isVisible()) {
229 deferHideParentMenus: function() {
230 Ext.menu.Manager.hideAll();
233 expandMenu: function(delay) {
237 clearTimeout(me.hideMenuTimer);
239 me.deferExpandMenu();
241 me.expandMenuTimer = Ext.defer(me.deferExpandMenu, Ext.isNumber(delay) ? delay : me.menuExpandDelay, me);
247 this.$focused = true;
248 this.callParent(arguments);
251 getRefItems: function(deep){
252 var menu = this.menu,
256 items = menu.getRefItems(deep);
262 hideMenu: function(delay) {
266 clearTimeout(me.expandMenuTimer);
267 me.hideMenuTimer = Ext.defer(me.deferHideMenu, Ext.isNumber(delay) ? delay : me.menuHideDelay, me);
271 initComponent: function() {
273 prefix = Ext.baseCSSPrefix,
274 cls = [prefix + 'menu-item'];
277 <span id='Ext-menu-Item-event-activate'> /**
278 </span> * @event activate
279 * Fires when this item is activated
280 * @param {Ext.menu.Item} item The activated item
284 <span id='Ext-menu-Item-event-click'> /**
285 </span> * @event click
286 * Fires when this item is clicked
287 * @param {Ext.menu.Item} item The item that was clicked
288 * @param {Ext.EventObject} e The underyling {@link Ext.EventObject}.
292 <span id='Ext-menu-Item-event-deactivate'> /**
293 </span> * @event deactivate
294 * Fires when this tiem is deactivated
295 * @param {Ext.menu.Item} item The deactivated item
301 cls.push(prefix + 'menu-item-plain');
308 me.cls = cls.join(' ');
311 me.menu = Ext.menu.Manager.get(me.menu);
314 me.callParent(arguments);
317 onClick: function(e) {
328 if (me.hideOnClick) {
329 me.deferHideParentMenusTimer = Ext.defer(me.deferHideParentMenus, me.clickHideDelay, me);
332 Ext.callback(me.handler, me.scope || me, [me, e]);
333 me.fireEvent('click', me, e);
335 if (!me.hideOnClick) {
340 onDestroy: function() {
343 clearTimeout(me.expandMenuTimer);
344 clearTimeout(me.hideMenuTimer);
345 clearTimeout(me.deferHideParentMenusTimer);
348 delete me.menu.parentItem;
349 delete me.menu.parentMenu;
350 delete me.menu.ownerCt;
351 if (me.destroyMenu !== false) {
355 me.callParent(arguments);
358 onRender: function(ct, pos) {
360 blank = Ext.BLANK_IMAGE_URL;
362 Ext.applyIf(me.renderData, {
363 href: me.href || '#',
364 hrefTarget: me.hrefTarget,
365 icon: me.icon || blank,
366 iconCls: me.iconCls + (me.checkChangeDisabled ? ' ' + me.disabledCls : ''),
367 menu: Ext.isDefined(me.menu),
373 me.addChildEls('itemEl', 'iconEl', 'textEl', 'arrowEl');
375 me.callParent(arguments);
378 <span id='Ext-menu-Item-method-setHandler'> /**
379 </span> * Sets the {@link #click} handler of this item
380 * @param {Function} fn The handler function
381 * @param {Object} scope (optional) The scope of the handler function
383 setHandler: function(fn, scope) {
384 this.handler = fn || null;
388 <span id='Ext-menu-Item-method-setIconCls'> /**
389 </span> * Sets the {@link #iconCls} of this item
390 * @param {String} iconCls The CSS class to set to {@link #iconCls}
392 setIconCls: function(iconCls) {
397 me.iconEl.removeCls(me.iconCls);
401 me.iconEl.addCls(iconCls);
405 me.iconCls = iconCls;
408 <span id='Ext-menu-Item-method-setText'> /**
409 </span> * Sets the {@link #text} of this item
410 * @param {String} text The {@link #text}
412 setText: function(text) {
414 el = me.textEl || me.el;
419 el.update(text || '');
420 // cannot just call doComponentLayout due to stretchmax
421 me.ownerCt.redoComponentLayout();