3 * Copyright(c) 2006-2009 Ext JS, LLC
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 = function(config){
18 Ext.menu.BaseItem.superclass.constructor.call(this, config);
23 * Fires when this item is clicked
24 * @param {Ext.menu.BaseItem} this
25 * @param {Ext.EventObject} e
30 * Fires when this item is activated
31 * @param {Ext.menu.BaseItem} this
36 * Fires when this item is deactivated
37 * @param {Ext.menu.BaseItem} this
43 this.on("click", this.handler, this.scope);
47 Ext.extend(Ext.menu.BaseItem, Ext.Component, {
49 * @property parentMenu
51 * The parent Menu of this Item.
54 * @cfg {Function} handler
55 * A function that will handle the click event of this menu item (optional).
56 * The handler is passed the following parameters:<div class="mdetail-params"><ul>
57 * <li><code>b</code> : Item<div class="sub-desc">This menu Item.</div></li>
58 * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
63 * The scope (<tt><b>this</b></tt> reference) in which the handler function will be called.
66 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
70 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
72 activeClass : "x-menu-item-active",
74 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
78 * @cfg {Number} clickHideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
83 ctype : "Ext.menu.BaseItem",
86 actionMode : "container",
89 onRender : function(container, position){
90 Ext.menu.BaseItem.superclass.onRender.apply(this, arguments);
91 if(this.ownerCt && this.ownerCt instanceof Ext.menu.Menu){
92 this.parentMenu = this.ownerCt;
94 this.container.addClass('x-menu-list-item');
95 this.mon(this.el, 'click', this.onClick, this);
96 this.mon(this.el, 'mouseenter', this.activate, this);
97 this.mon(this.el, 'mouseleave', this.deactivate, this);
102 * Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
103 * config property). If an existing handler is already registered, it will be unregistered for you.
104 * @param {Function} handler The function that should be called on click
105 * @param {Object} scope The scope that should be passed to the handler
107 setHandler : function(handler, scope){
109 this.un("click", this.handler, this.scope);
111 this.on("click", this.handler = handler, this.scope = scope);
115 onClick : function(e){
116 if(!this.disabled && this.fireEvent("click", this, e) !== false
117 && (this.parentMenu && this.parentMenu.fireEvent("itemclick", this, e) !== false)){
125 activate : function(){
129 var li = this.container;
130 li.addClass(this.activeClass);
131 this.region = li.getRegion().adjust(2, 2, -2, -2);
132 this.fireEvent("activate", this);
137 deactivate : function(){
138 this.container.removeClass(this.activeClass);
139 this.fireEvent("deactivate", this);
143 shouldDeactivate : function(e){
144 return !this.region || !this.region.contains(e.getPoint());
148 handleClick : function(e){
149 if(this.hideOnClick){
150 this.parentMenu.hide.defer(this.clickHideDelay, this.parentMenu, [true]);
154 // private. Do nothing
155 expandMenu : Ext.emptyFn,
157 // private. Do nothing
158 hideMenu : Ext.emptyFn
160 Ext.reg('menubaseitem', Ext.menu.BaseItem);