3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.menu.BaseItem
9 * @extends Ext.Component
10 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
11 * management and base configuration options shared by all menu components.
13 * Creates a new BaseItem
14 * @param {Object} config Configuration options
17 Ext.menu.BaseItem = Ext.extend(Ext.Component, {
19 * @property parentMenu
21 * The parent Menu of this Item.
24 * @cfg {Function} handler
25 * A function that will handle the click event of this menu item (optional).
26 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
27 * <li><code>b</code> : Item<div class="sub-desc">This menu Item.</div></li>
28 * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
33 * The scope (<tt><b>this</b></tt> reference) in which the handler function will be called.
36 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
40 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
42 activeClass : "x-menu-item-active",
44 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
48 * @cfg {Number} clickHideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 1)
53 ctype : "Ext.menu.BaseItem",
56 actionMode : "container",
58 initComponent : function(){
59 Ext.menu.BaseItem.superclass.initComponent.call(this);
63 * Fires when this item is clicked
64 * @param {Ext.menu.BaseItem} this
65 * @param {Ext.EventObject} e
70 * Fires when this item is activated
71 * @param {Ext.menu.BaseItem} this
76 * Fires when this item is deactivated
77 * @param {Ext.menu.BaseItem} this
82 this.on("click", this.handler, this.scope);
87 onRender : function(container, position){
88 Ext.menu.BaseItem.superclass.onRender.apply(this, arguments);
89 if(this.ownerCt && this.ownerCt instanceof Ext.menu.Menu){
90 this.parentMenu = this.ownerCt;
92 this.container.addClass('x-menu-list-item');
96 mouseenter: this.activate,
97 mouseleave: this.deactivate
103 * Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
104 * config property). If an existing handler is already registered, it will be unregistered for you.
105 * @param {Function} handler The function that should be called on click
106 * @param {Object} scope The scope (<code>this</code> reference) in which the handler function is executed. Defaults to this menu item.
108 setHandler : function(handler, scope){
110 this.un("click", this.handler, this.scope);
112 this.on("click", this.handler = handler, this.scope = scope);
116 onClick : function(e){
117 if(!this.disabled && this.fireEvent("click", this, e) !== false
118 && (this.parentMenu && this.parentMenu.fireEvent("itemclick", this, e) !== false)){
126 activate : function(){
130 var li = this.container;
131 li.addClass(this.activeClass);
132 this.region = li.getRegion().adjust(2, 2, -2, -2);
133 this.fireEvent("activate", this);
138 deactivate : function(){
139 this.container.removeClass(this.activeClass);
140 this.fireEvent("deactivate", this);
144 shouldDeactivate : function(e){
145 return !this.region || !this.region.contains(e.getPoint());
149 handleClick : function(e){
150 var pm = this.parentMenu;
151 if(this.hideOnClick){
153 pm.hide.defer(this.clickHideDelay, pm, [true]);
155 pm.deactivateActive();
160 // private. Do nothing
161 expandMenu : Ext.emptyFn,
163 // private. Do nothing
164 hideMenu : Ext.emptyFn
166 Ext.reg('menubaseitem', Ext.menu.BaseItem);