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.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)
66 <div id="cfg-Ext.menu.Item-altText"></div>/**
67 * @cfg {String} altText The altText to use for the icon, if it exists. Defaults to <tt>''</tt>.
75 ctype: 'Ext.menu.Item',
77 initComponent : function(){
78 Ext.menu.Item.superclass.initComponent.call(this);
80 this.menu = Ext.menu.MenuMgr.get(this.menu);
81 this.menu.ownerCt = this;
86 onRender : function(container, position){
88 this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
89 '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',
90 '<tpl if="hrefTarget">',
91 ' target="{hrefTarget}"',
94 '<img alt="{altText}" src="{icon}" class="x-menu-item-icon {iconCls}"/>',
95 '<span class="x-menu-item-text">{text}</span>',
99 var a = this.getTemplateArgs();
100 this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
101 this.iconEl = this.el.child('img.x-menu-item-icon');
102 this.textEl = this.el.child('.x-menu-item-text');
103 if(!this.href) { // if no link defined, prevent the default anchor event
104 this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
106 Ext.menu.Item.superclass.onRender.call(this, container, position);
109 getTemplateArgs: function() {
112 cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
113 href: this.href || '#',
114 hrefTarget: this.hrefTarget,
115 icon: this.icon || Ext.BLANK_IMAGE_URL,
116 iconCls: this.iconCls || '',
117 text: this.itemText||this.text||' ',
118 altText: this.altText || ''
122 <div id="method-Ext.menu.Item-setText"></div>/**
123 * Sets the text to display in this menu item
124 * @param {String} text The text to display
126 setText : function(text){
127 this.text = text||' ';
129 this.textEl.update(this.text);
130 this.parentMenu.layout.doAutoSize();
134 <div id="method-Ext.menu.Item-setIconClass"></div>/**
135 * Sets the CSS class to apply to the item's icon element
136 * @param {String} cls The CSS class to apply
138 setIconClass : function(cls){
139 var oldCls = this.iconCls;
142 this.iconEl.replaceClass(oldCls, this.iconCls);
147 beforeDestroy: function(){
149 delete this.menu.ownerCt;
152 Ext.menu.Item.superclass.beforeDestroy.call(this);
156 handleClick : function(e){
157 if(!this.href){ // if no link defined, stop the event automatically
160 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
164 activate : function(autoExpand){
165 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
175 shouldDeactivate : function(e){
176 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
177 if(this.menu && this.menu.isVisible()){
178 return !this.menu.getEl().getRegion().contains(e.getPoint());
186 deactivate : function(){
187 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
192 expandMenu : function(autoActivate){
193 if(!this.disabled && this.menu){
194 clearTimeout(this.hideTimer);
195 delete this.hideTimer;
196 if(!this.menu.isVisible() && !this.showTimer){
197 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
198 }else if (this.menu.isVisible() && autoActivate){
199 this.menu.tryActivate(0, 1);
205 deferExpand : function(autoActivate){
206 delete this.showTimer;
207 this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
209 this.menu.tryActivate(0, 1);
214 hideMenu : function(){
215 clearTimeout(this.showTimer);
216 delete this.showTimer;
217 if(!this.hideTimer && this.menu && this.menu.isVisible()){
218 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
223 deferHide : function(){
224 delete this.hideTimer;
226 this.parentMenu.setActiveItem(this, false);
232 Ext.reg('menuitem', Ext.menu.Item);</pre>