BaseItem_wev8.js
4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.menu.BaseItem
* @extends Ext.Component
* The base class for all items that render into menus. BaseItem provides default rendering, activated state
* management and base configuration options shared by all menu components.
* @constructor
* Creates a new BaseItem
* @param {Object} config Configuration options
*/
Ext.menu.BaseItem = function(config){
Ext.menu.BaseItem.superclass.constructor.call(this, config);
this.addEvents(
/**
* @event click
* Fires when this item is clicked
* @param {Ext.menu.BaseItem} this
* @param {Ext.EventObject} e
*/
'click',
/**
* @event activate
* Fires when this item is activated
* @param {Ext.menu.BaseItem} this
*/
'activate',
/**
* @event deactivate
* Fires when this item is deactivated
* @param {Ext.menu.BaseItem} this
*/
'deactivate'
);
if(this.handler){
this.on("click", this.handler, this.scope);
}
};
Ext.extend(Ext.menu.BaseItem, Ext.Component, {
/**
* @cfg {Function} handler
* A function that will handle the click event of this menu item (defaults to undefined)
*/
/**
* @cfg {Object} scope
* The scope in which the handler function will be called.
*/
/**
* @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
*/
canActivate : false,
/**
* @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
*/
activeClass : "x-menu-item-active",
/**
* @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
*/
hideOnClick : true,
/**
* @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
*/
hideDelay : 100,
// private
ctype: "Ext.menu.BaseItem",
// private
actionMode : "container",
// private
render : function(container, parentMenu){
this.parentMenu = parentMenu;
Ext.menu.BaseItem.superclass.render.call(this, container);
this.container.menuItemId = this.id;
},
// private
onRender : function(container, position){
this.el = Ext.get(this.el);
container.dom.appendChild(this.el.dom);
},
/**
* Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
* config property). If an existing handler is already registered, it will be unregistered for you.
* @param {Function} handler The function that should be called on click
* @param {Object} scope The scope that should be passed to the handler
*/
setHandler : function(handler, scope){
if(this.handler){
this.un("click", this.handler, this.scope);
}
this.on("click", this.handler = handler, this.scope = scope);
},
// private
onClick : function(e){
if(!this.disabled && this.fireEvent("click", this, e) !== false
&& this.parentMenu.fireEvent("itemclick", this, e) !== false){
this.handleClick(e);
}else{
e.stopEvent();
}
},
// private
activate : function(){
if(this.disabled){
return false;
}
var li = this.container;
li.addClass(this.activeClass);
this.region = li.getRegion().adjust(2, 2, -2, -2);
this.fireEvent("activate", this);
return true;
},
// private
deactivate : function(){
this.container.removeClass(this.activeClass);
this.fireEvent("deactivate", this);
},
// private
shouldDeactivate : function(e){
return !this.region || !this.region.contains(e.getPoint());
},
// private
handleClick : function(e){
if(this.hideOnClick){
this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
}
},
// private
expandMenu : function(autoActivate){
// do nothing
},
// private
hideMenu : function(){
// do nothing
}
});