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.2
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.menu.Item"></div>/**
16 * @class Ext.menu.Item
17 * @extends Ext.menu.BaseItem
18 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
19 * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
20 * activation and click handling.
23 * @param {Object} config Configuration options
26 Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {
27 <div id="prop-Ext.menu.Item-menu"></div>/**
30 * The submenu associated with this Item if one was configured.
32 <div id="cfg-Ext.menu.Item-menu"></div>/**
33 * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
34 * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
36 <div id="cfg-Ext.menu.Item-icon"></div>/**
37 * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
38 * icon is specified {@link #iconCls} should not be.
40 <div id="cfg-Ext.menu.Item-iconCls"></div>/**
41 * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
42 * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
44 <div id="cfg-Ext.menu.Item-text"></div>/**
45 * @cfg {String} text The text to display in this item (defaults to '').
47 <div id="cfg-Ext.menu.Item-href"></div>/**
48 * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
50 <div id="cfg-Ext.menu.Item-hrefTarget"></div>/**
51 * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
53 <div id="cfg-Ext.menu.Item-itemCls"></div>/**
54 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
56 itemCls : 'x-menu-item',
57 <div id="cfg-Ext.menu.Item-canActivate"></div>/**
58 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
61 <div id="cfg-Ext.menu.Item-showDelay"></div>/**
62 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
69 ctype: 'Ext.menu.Item',
71 initComponent : function(){
72 Ext.menu.Item.superclass.initComponent.call(this);
74 this.menu = Ext.menu.MenuMgr.get(this.menu);
75 this.menu.ownerCt = this;
80 onRender : function(container, position){
82 this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
83 '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',
84 '<tpl if="hrefTarget">',
85 ' target="{hrefTarget}"',
88 '<img src="{icon}" class="x-menu-item-icon {iconCls}"/>',
89 '<span class="x-menu-item-text">{text}</span>',
93 var a = this.getTemplateArgs();
94 this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
95 this.iconEl = this.el.child('img.x-menu-item-icon');
96 this.textEl = this.el.child('.x-menu-item-text');
97 if(!this.href) { // if no link defined, prevent the default anchor event
98 this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
100 Ext.menu.Item.superclass.onRender.call(this, container, position);
103 getTemplateArgs: function() {
106 cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
107 href: this.href || '#',
108 hrefTarget: this.hrefTarget,
109 icon: this.icon || Ext.BLANK_IMAGE_URL,
110 iconCls: this.iconCls || '',
111 text: this.itemText||this.text||' '
115 <div id="method-Ext.menu.Item-setText"></div>/**
116 * Sets the text to display in this menu item
117 * @param {String} text The text to display
119 setText : function(text){
120 this.text = text||' ';
122 this.textEl.update(this.text);
123 this.parentMenu.layout.doAutoSize();
127 <div id="method-Ext.menu.Item-setIconClass"></div>/**
128 * Sets the CSS class to apply to the item's icon element
129 * @param {String} cls The CSS class to apply
131 setIconClass : function(cls){
132 var oldCls = this.iconCls;
135 this.iconEl.replaceClass(oldCls, this.iconCls);
140 beforeDestroy: function(){
142 delete this.menu.ownerCt;
145 Ext.menu.Item.superclass.beforeDestroy.call(this);
149 handleClick : function(e){
150 if(!this.href){ // if no link defined, stop the event automatically
153 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
157 activate : function(autoExpand){
158 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
168 shouldDeactivate : function(e){
169 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
170 if(this.menu && this.menu.isVisible()){
171 return !this.menu.getEl().getRegion().contains(e.getPoint());
179 deactivate : function(){
180 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
185 expandMenu : function(autoActivate){
186 if(!this.disabled && this.menu){
187 clearTimeout(this.hideTimer);
188 delete this.hideTimer;
189 if(!this.menu.isVisible() && !this.showTimer){
190 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
191 }else if (this.menu.isVisible() && autoActivate){
192 this.menu.tryActivate(0, 1);
198 deferExpand : function(autoActivate){
199 delete this.showTimer;
200 this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
202 this.menu.tryActivate(0, 1);
207 hideMenu : function(){
208 clearTimeout(this.showTimer);
209 delete this.showTimer;
210 if(!this.hideTimer && this.menu && this.menu.isVisible()){
211 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
216 deferHide : function(){
217 delete this.hideTimer;
219 this.parentMenu.setActiveItem(this, false);
225 Ext.reg('menuitem', Ext.menu.Item);</pre>