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.BaseItem
\r
11 * @extends Ext.Component
\r
12 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
\r
13 * management and base configuration options shared by all menu components.
\r
15 * Creates a new BaseItem
\r
16 * @param {Object} config Configuration options
\r
18 Ext.menu.BaseItem = function(config){
\r
19 Ext.menu.BaseItem.superclass.constructor.call(this, config);
\r
24 * Fires when this item is clicked
\r
25 * @param {Ext.menu.BaseItem} this
\r
26 * @param {Ext.EventObject} e
\r
31 * Fires when this item is activated
\r
32 * @param {Ext.menu.BaseItem} this
\r
37 * Fires when this item is deactivated
\r
38 * @param {Ext.menu.BaseItem} this
\r
44 this.on("click", this.handler, this.scope);
\r
48 Ext.extend(Ext.menu.BaseItem, Ext.Component, {
\r
50 * @cfg {Function} handler
\r
51 * A function that will handle the click event of this menu item (defaults to undefined)
\r
54 * @cfg {Object} scope
\r
55 * The scope in which the handler function will be called.
\r
58 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
\r
60 canActivate : false,
\r
62 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
\r
64 activeClass : "x-menu-item-active",
\r
66 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
\r
70 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
\r
75 ctype: "Ext.menu.BaseItem",
\r
78 actionMode : "container",
\r
81 render : function(container, parentMenu){
\r
83 * The parent Menu of this Item.
\r
84 * @property parentMenu
\r
85 * @type Ext.menu.Menu
\r
87 this.parentMenu = parentMenu;
\r
88 Ext.menu.BaseItem.superclass.render.call(this, container);
\r
89 this.container.menuItemId = this.id;
\r
93 onRender : function(container, position){
\r
94 this.el = Ext.get(this.el);
\r
96 this.el.id = this.id;
\r
98 container.dom.appendChild(this.el.dom);
\r
102 * Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
\r
103 * config property). If an existing handler is already registered, it will be unregistered for you.
\r
104 * @param {Function} handler The function that should be called on click
\r
105 * @param {Object} scope The scope that should be passed to the handler
\r
107 setHandler : function(handler, scope){
\r
109 this.un("click", this.handler, this.scope);
\r
111 this.on("click", this.handler = handler, this.scope = scope);
\r
115 onClick : function(e){
\r
116 if(!this.disabled && this.fireEvent("click", this, e) !== false
\r
117 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
\r
118 this.handleClick(e);
\r
125 activate : function(){
\r
129 var li = this.container;
\r
130 li.addClass(this.activeClass);
\r
131 this.region = li.getRegion().adjust(2, 2, -2, -2);
\r
132 this.fireEvent("activate", this);
\r
137 deactivate : function(){
\r
138 this.container.removeClass(this.activeClass);
\r
139 this.fireEvent("deactivate", this);
\r
143 shouldDeactivate : function(e){
\r
144 return !this.region || !this.region.contains(e.getPoint());
\r
148 handleClick : function(e){
\r
149 if(this.hideOnClick){
\r
150 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
\r
155 expandMenu : function(autoActivate){
\r
160 hideMenu : function(){
\r