2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\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
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
27 * @cfg {Mixed} menu 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
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
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
39 * @cfg {String} text The text to display in this item (defaults to '').
\r
42 * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
\r
45 * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
\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
52 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
\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
66 onRender : function(container, position){
\r
67 var el = document.createElement("a");
\r
68 el.hideFocus = true;
\r
69 el.unselectable = "on";
\r
70 el.href = this.href || "#";
\r
71 if(this.hrefTarget){
\r
72 el.target = this.hrefTarget;
\r
74 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
\r
75 el.innerHTML = String.format(
\r
76 '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
\r
77 this.icon || Ext.BLANK_IMAGE_URL, this.itemText||this.text, this.iconCls || '');
\r
79 Ext.menu.Item.superclass.onRender.call(this, container, position);
\r
83 * Sets the text to display in this menu item
\r
84 * @param {String} text The text to display
\r
86 setText : function(text){
\r
89 this.el.update(String.format(
\r
90 '<img src="{0}" class="x-menu-item-icon {2}">{1}',
\r
91 this.icon || Ext.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
\r
92 this.parentMenu.autoWidth();
\r
97 * Sets the CSS class to apply to the item's icon element
\r
98 * @param {String} cls The CSS class to apply
\r
100 setIconClass : function(cls){
\r
101 var oldCls = this.iconCls;
\r
102 this.iconCls = cls;
\r
104 this.el.child('img.x-menu-item-icon').replaceClass(oldCls, this.iconCls);
\r
109 beforeDestroy: function(){
\r
111 this.menu.destroy();
\r
113 Ext.menu.Item.superclass.beforeDestroy.call(this);
\r
117 handleClick : function(e){
\r
118 if(!this.href){ // if no link defined, stop the event automatically
\r
121 Ext.menu.Item.superclass.handleClick.apply(this, arguments);
\r
125 activate : function(autoExpand){
\r
126 if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
\r
136 shouldDeactivate : function(e){
\r
137 if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
\r
138 if(this.menu && this.menu.isVisible()){
\r
139 return !this.menu.getEl().getRegion().contains(e.getPoint());
\r
147 deactivate : function(){
\r
148 Ext.menu.Item.superclass.deactivate.apply(this, arguments);
\r
153 expandMenu : function(autoActivate){
\r
154 if(!this.disabled && this.menu){
\r
155 clearTimeout(this.hideTimer);
\r
156 delete this.hideTimer;
\r
157 if(!this.menu.isVisible() && !this.showTimer){
\r
158 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
\r
159 }else if (this.menu.isVisible() && autoActivate){
\r
160 this.menu.tryActivate(0, 1);
\r
166 deferExpand : function(autoActivate){
\r
167 delete this.showTimer;
\r
168 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
\r
170 this.menu.tryActivate(0, 1);
\r
175 hideMenu : function(){
\r
176 clearTimeout(this.showTimer);
\r
177 delete this.showTimer;
\r
178 if(!this.hideTimer && this.menu && this.menu.isVisible()){
\r
179 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
\r
184 deferHide : function(){
\r
185 delete this.hideTimer;
\r
186 if(this.menu.over){
\r
187 this.parentMenu.setActiveItem(this, false);
\r