3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.menu.Item"></div>/**
\r
15 * @class Ext.menu.Item
\r
16 * @extends Ext.menu.BaseItem
\r
17 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
\r
18 * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
\r
19 * activation and click handling.
\r
21 * Creates a new Item
\r
22 * @param {Object} config Configuration options
\r
25 Ext.menu.Item = function(config){
\r
26 Ext.menu.Item.superclass.constructor.call(this, config);
\r
28 this.menu = Ext.menu.MenuMgr.get(this.menu);
\r
31 Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, {
\r
32 <div id="prop-Ext.menu.Item-menu"></div>/**
\r
34 * @type Ext.menu.Menu
\r
35 * The submenu associated with this Item if one was configured.
\r
37 <div id="cfg-Ext.menu.Item-menu"></div>/**
\r
38 * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
\r
39 * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
\r
41 <div id="cfg-Ext.menu.Item-icon"></div>/**
\r
42 * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
\r
43 * icon is specified {@link #iconCls} should not be.
\r
45 <div id="cfg-Ext.menu.Item-iconCls"></div>/**
\r
46 * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
\r
47 * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
\r
49 <div id="cfg-Ext.menu.Item-text"></div>/**
\r
50 * @cfg {String} text The text to display in this item (defaults to '').
\r
52 <div id="cfg-Ext.menu.Item-href"></div>/**
\r
53 * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
\r
55 <div id="cfg-Ext.menu.Item-hrefTarget"></div>/**
\r
56 * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
\r
58 <div id="cfg-Ext.menu.Item-itemCls"></div>/**
\r
59 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
\r
61 itemCls : 'x-menu-item',
\r
62 <div id="cfg-Ext.menu.Item-canActivate"></div>/**
\r
63 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
\r
66 <div id="cfg-Ext.menu.Item-showDelay"></div>/**
\r
67 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
\r
70 // doc'd in BaseItem
\r
74 ctype: 'Ext.menu.Item',
\r
77 onRender : function(container, position){
\r
78 if (!this.itemTpl) {
\r
79 this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
\r
80 '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',
\r
81 '<tpl if="hrefTarget">',
\r
82 ' target="{hrefTarget}"',
\r
85 '<img src="{icon}" class="x-menu-item-icon {iconCls}"/>',
\r
86 '<span class="x-menu-item-text">{text}</span>',
\r
90 var a = this.getTemplateArgs();
\r
91 this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
\r
92 this.iconEl = this.el.child('img.x-menu-item-icon');
\r
93 this.textEl = this.el.child('.x-menu-item-text');
\r
94 Ext.menu.Item.superclass.onRender.call(this, container, position);
\r
97 getTemplateArgs: function() {
\r
100 cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
\r
101 href: this.href || '#',
\r
102 hrefTarget: this.hrefTarget,
\r
103 icon: this.icon || Ext.BLANK_IMAGE_URL,
\r
104 iconCls: this.iconCls || '',
\r
105 text: this.itemText||this.text||' '
\r
109 <div id="method-Ext.menu.Item-setText"></div>/**
\r
110 * Sets the text to display in this menu item
\r
111 * @param {String} text The text to display
\r
113 setText : function(text){
\r
114 this.text = text||' ';
\r
116 this.textEl.update(this.text);
\r
117 this.parentMenu.layout.doAutoSize();
\r
121 <div id="method-Ext.menu.Item-setIconClass"></div>/**
\r
122 * Sets the CSS class to apply to the item's icon element
\r
123 * @param {String} cls The CSS class to apply
\r
125 setIconClass : function(cls){
\r
126 var oldCls = this.iconCls;
\r
127 this.iconCls = cls;
\r
129 this.iconEl.replaceClass(oldCls, this.iconCls);
\r
134 beforeDestroy: function(){
\r
136 this.menu.destroy();
\r
138 Ext.menu.Item.superclass.beforeDestroy.call(this);
\r
142 handleClick : function(e){
\r
143 if(!this.href){ // if no link defined, stop the event automatically
\r
146 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
\r
150 activate : function(autoExpand){
\r
151 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
\r
161 shouldDeactivate : function(e){
\r
162 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
\r
163 if(this.menu && this.menu.isVisible()){
\r
164 return !this.menu.getEl().getRegion().contains(e.getPoint());
\r
172 deactivate : function(){
\r
173 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
\r
178 expandMenu : function(autoActivate){
\r
179 if(!this.disabled && this.menu){
\r
180 clearTimeout(this.hideTimer);
\r
181 delete this.hideTimer;
\r
182 if(!this.menu.isVisible() && !this.showTimer){
\r
183 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
\r
184 }else if (this.menu.isVisible() && autoActivate){
\r
185 this.menu.tryActivate(0, 1);
\r
191 deferExpand : function(autoActivate){
\r
192 delete this.showTimer;
\r
193 this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
\r
195 this.menu.tryActivate(0, 1);
\r
200 hideMenu : function(){
\r
201 clearTimeout(this.showTimer);
\r
202 delete this.showTimer;
\r
203 if(!this.hideTimer && this.menu && this.menu.isVisible()){
\r
204 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
\r
209 deferHide : function(){
\r
210 delete this.hideTimer;
\r
211 if(this.menu.over){
\r
212 this.parentMenu.setActiveItem(this, false);
\r
218 Ext.reg('menuitem', Ext.menu.Item);</pre>