3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.menu.Item"></div>/**
\r
10 * @class Ext.menu.Item
\r
11 * @extends Ext.menu.BaseItem
\r
12 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
\r
13 * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
\r
14 * activation and click handling.
\r
16 * Creates a new Item
\r
17 * @param {Object} config Configuration options
\r
20 Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {
\r
21 <div id="prop-Ext.menu.Item-menu"></div>/**
\r
23 * @type Ext.menu.Menu
\r
24 * The submenu associated with this Item if one was configured.
\r
26 <div id="cfg-Ext.menu.Item-menu"></div>/**
\r
27 * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
\r
28 * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
\r
30 <div id="cfg-Ext.menu.Item-icon"></div>/**
\r
31 * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
\r
32 * icon is specified {@link #iconCls} should not be.
\r
34 <div id="cfg-Ext.menu.Item-iconCls"></div>/**
\r
35 * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
\r
36 * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
\r
38 <div id="cfg-Ext.menu.Item-text"></div>/**
\r
39 * @cfg {String} text The text to display in this item (defaults to '').
\r
41 <div id="cfg-Ext.menu.Item-href"></div>/**
\r
42 * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
\r
44 <div id="cfg-Ext.menu.Item-hrefTarget"></div>/**
\r
45 * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
\r
47 <div id="cfg-Ext.menu.Item-itemCls"></div>/**
\r
48 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
\r
50 itemCls : 'x-menu-item',
\r
51 <div id="cfg-Ext.menu.Item-canActivate"></div>/**
\r
52 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
\r
55 <div id="cfg-Ext.menu.Item-showDelay"></div>/**
\r
56 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
\r
59 // doc'd in BaseItem
\r
63 ctype: 'Ext.menu.Item',
\r
65 initComponent : function(){
\r
66 Ext.menu.Item.superclass.initComponent.call(this);
\r
68 this.menu = Ext.menu.MenuMgr.get(this.menu);
\r
69 this.menu.ownerCt = this;
\r
74 onRender : function(container, position){
\r
75 if (!this.itemTpl) {
\r
76 this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
\r
77 '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',
\r
78 '<tpl if="hrefTarget">',
\r
79 ' target="{hrefTarget}"',
\r
82 '<img src="{icon}" class="x-menu-item-icon {iconCls}"/>',
\r
83 '<span class="x-menu-item-text">{text}</span>',
\r
87 var a = this.getTemplateArgs();
\r
88 this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
\r
89 this.iconEl = this.el.child('img.x-menu-item-icon');
\r
90 this.textEl = this.el.child('.x-menu-item-text');
\r
91 if(!this.href) { // if no link defined, prevent the default anchor event
\r
92 this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
\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 delete this.menu.ownerCt;
\r
137 this.menu.destroy();
\r
139 Ext.menu.Item.superclass.beforeDestroy.call(this);
\r
143 handleClick : function(e){
\r
144 if(!this.href){ // if no link defined, stop the event automatically
\r
147 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
\r
151 activate : function(autoExpand){
\r
152 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
\r
162 shouldDeactivate : function(e){
\r
163 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
\r
164 if(this.menu && this.menu.isVisible()){
\r
165 return !this.menu.getEl().getRegion().contains(e.getPoint());
\r
173 deactivate : function(){
\r
174 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
\r
179 expandMenu : function(autoActivate){
\r
180 if(!this.disabled && this.menu){
\r
181 clearTimeout(this.hideTimer);
\r
182 delete this.hideTimer;
\r
183 if(!this.menu.isVisible() && !this.showTimer){
\r
184 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
\r
185 }else if (this.menu.isVisible() && autoActivate){
\r
186 this.menu.tryActivate(0, 1);
\r
192 deferExpand : function(autoActivate){
\r
193 delete this.showTimer;
\r
194 this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
\r
196 this.menu.tryActivate(0, 1);
\r
201 hideMenu : function(){
\r
202 clearTimeout(this.showTimer);
\r
203 delete this.showTimer;
\r
204 if(!this.hideTimer && this.menu && this.menu.isVisible()){
\r
205 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
\r
210 deferHide : function(){
\r
211 delete this.hideTimer;
\r
212 if(this.menu.over){
\r
213 this.parentMenu.setActiveItem(this, false);
\r
219 Ext.reg('menuitem', Ext.menu.Item);</pre>
\r