3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.menu.Item"></div>/**
\r
9 * @class Ext.menu.Item
\r
10 * @extends Ext.menu.BaseItem
\r
11 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
\r
12 * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
\r
13 * activation and click handling.
\r
15 * Creates a new Item
\r
16 * @param {Object} config Configuration options
\r
19 Ext.menu.Item = function(config){
\r
20 Ext.menu.Item.superclass.constructor.call(this, config);
\r
22 this.menu = Ext.menu.MenuMgr.get(this.menu);
\r
25 Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, {
\r
26 <div id="prop-Ext.menu.Item-menu"></div>/**
\r
28 * @type Ext.menu.Menu
\r
29 * The submenu associated with this Item if one was configured.
\r
31 <div id="cfg-Ext.menu.Item-menu"></div>/**
\r
32 * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
\r
33 * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
\r
35 <div id="cfg-Ext.menu.Item-icon"></div>/**
\r
36 * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
\r
37 * icon is specified {@link #iconCls} should not be.
\r
39 <div id="cfg-Ext.menu.Item-iconCls"></div>/**
\r
40 * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
\r
41 * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
\r
43 <div id="cfg-Ext.menu.Item-text"></div>/**
\r
44 * @cfg {String} text The text to display in this item (defaults to '').
\r
46 <div id="cfg-Ext.menu.Item-href"></div>/**
\r
47 * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
\r
49 <div id="cfg-Ext.menu.Item-hrefTarget"></div>/**
\r
50 * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
\r
52 <div id="cfg-Ext.menu.Item-itemCls"></div>/**
\r
53 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
\r
55 itemCls : 'x-menu-item',
\r
56 <div id="cfg-Ext.menu.Item-canActivate"></div>/**
\r
57 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
\r
60 <div id="cfg-Ext.menu.Item-showDelay"></div>/**
\r
61 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
\r
64 // doc'd in BaseItem
\r
68 ctype: 'Ext.menu.Item',
\r
71 onRender : function(container, position){
\r
72 if (!this.itemTpl) {
\r
73 this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
\r
74 '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',
\r
75 '<tpl if="hrefTarget">',
\r
76 ' target="{hrefTarget}"',
\r
79 '<img src="{icon}" class="x-menu-item-icon {iconCls}"/>',
\r
80 '<span class="x-menu-item-text">{text}</span>',
\r
84 var a = this.getTemplateArgs();
\r
85 this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
\r
86 this.iconEl = this.el.child('img.x-menu-item-icon');
\r
87 this.textEl = this.el.child('.x-menu-item-text');
\r
88 Ext.menu.Item.superclass.onRender.call(this, container, position);
\r
91 getTemplateArgs: function() {
\r
94 cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
\r
95 href: this.href || '#',
\r
96 hrefTarget: this.hrefTarget,
\r
97 icon: this.icon || Ext.BLANK_IMAGE_URL,
\r
98 iconCls: this.iconCls || '',
\r
99 text: this.itemText||this.text||' '
\r
103 <div id="method-Ext.menu.Item-setText"></div>/**
\r
104 * Sets the text to display in this menu item
\r
105 * @param {String} text The text to display
\r
107 setText : function(text){
\r
108 this.text = text||' ';
\r
110 this.textEl.update(this.text);
\r
111 this.parentMenu.layout.doAutoSize();
\r
115 <div id="method-Ext.menu.Item-setIconClass"></div>/**
\r
116 * Sets the CSS class to apply to the item's icon element
\r
117 * @param {String} cls The CSS class to apply
\r
119 setIconClass : function(cls){
\r
120 var oldCls = this.iconCls;
\r
121 this.iconCls = cls;
\r
123 this.iconEl.replaceClass(oldCls, this.iconCls);
\r
128 beforeDestroy: function(){
\r
130 this.menu.destroy();
\r
132 Ext.menu.Item.superclass.beforeDestroy.call(this);
\r
136 handleClick : function(e){
\r
137 if(!this.href){ // if no link defined, stop the event automatically
\r
140 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
\r
144 activate : function(autoExpand){
\r
145 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
\r
155 shouldDeactivate : function(e){
\r
156 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
\r
157 if(this.menu && this.menu.isVisible()){
\r
158 return !this.menu.getEl().getRegion().contains(e.getPoint());
\r
166 deactivate : function(){
\r
167 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
\r
172 expandMenu : function(autoActivate){
\r
173 if(!this.disabled && this.menu){
\r
174 clearTimeout(this.hideTimer);
\r
175 delete this.hideTimer;
\r
176 if(!this.menu.isVisible() && !this.showTimer){
\r
177 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
\r
178 }else if (this.menu.isVisible() && autoActivate){
\r
179 this.menu.tryActivate(0, 1);
\r
185 deferExpand : function(autoActivate){
\r
186 delete this.showTimer;
\r
187 this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
\r
189 this.menu.tryActivate(0, 1);
\r
194 hideMenu : function(){
\r
195 clearTimeout(this.showTimer);
\r
196 delete this.showTimer;
\r
197 if(!this.hideTimer && this.menu && this.menu.isVisible()){
\r
198 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
\r
203 deferHide : function(){
\r
204 delete this.hideTimer;
\r
205 if(this.menu.over){
\r
206 this.parentMenu.setActiveItem(this, false);
\r
212 Ext.reg('menuitem', Ext.menu.Item);</pre>
\r