Item_wev8.js
5.48 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.menu.Item
* @extends Ext.menu.BaseItem
* A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
* display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
* activation and click handling.
* @constructor
* Creates a new Item
* @param {Object} config Configuration options
*/
Ext.menu.Item = function(config){
Ext.menu.Item.superclass.constructor.call(this, config);
if(this.menu){
this.menu = Ext.menu.MenuMgr.get(this.menu);
}
};
Ext.extend(Ext.menu.Item, Ext.menu.BaseItem, {
/**
* @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
* icon is specified {@link #iconCls} should not be.
*/
/**
* @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
* this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
*/
/**
* @cfg {String} text The text to display in this item (defaults to '').
*/
/**
* @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
*/
/**
* @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
*/
/**
* @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
*/
itemCls : "x-menu-item",
/**
* @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
*/
canActivate : true,
/**
* @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
*/
showDelay: 200,
// doc'd in BaseItem
hideDelay: 200,
// private
ctype: "Ext.menu.Item",
// private
onRender : function(container, position){
var el = document.createElement("a");
el.hideFocus = true;
el.unselectable = "on";
el.href = this.href || "#";
if(this.hrefTarget){
el.target = this.hrefTarget;
}
el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
el.innerHTML = String.format(
'<img src="{0}" class="x-menu-item-icon {2}" />{1}',
this.icon || Ext.BLANK_IMAGE_URL, this.itemText||this.text, this.iconCls || '');
this.el = el;
Ext.menu.Item.superclass.onRender.call(this, container, position);
},
/**
* Sets the text to display in this menu item
* @param {String} text The text to display
*/
setText : function(text){
this.text = text;
if(this.rendered){
this.el.update(String.format(
'<img src="{0}" class="x-menu-item-icon {2}">{1}',
this.icon || Ext.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
this.parentMenu.autoWidth();
}
},
/**
* Sets the CSS class to apply to the item's icon element
* @param {String} cls The CSS class to apply
*/
setIconClass : function(cls){
var oldCls = this.iconCls;
this.iconCls = cls;
if(this.rendered){
this.el.child('img.x-menu-item-icon').replaceClass(oldCls, this.iconCls);
}
},
// private
handleClick : function(e){
if(!this.href){ // if no link defined, stop the event automatically
e.stopEvent();
}
Ext.menu.Item.superclass.handleClick.apply(this, arguments);
},
// private
activate : function(autoExpand){
if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
this.focus();
if(autoExpand){
this.expandMenu();
}
}
return true;
},
// private
shouldDeactivate : function(e){
if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
if(this.menu && this.menu.isVisible()){
return !this.menu.getEl().getRegion().contains(e.getPoint());
}
return true;
}
return false;
},
// private
deactivate : function(){
Ext.menu.Item.superclass.deactivate.apply(this, arguments);
this.hideMenu();
},
// private
expandMenu : function(autoActivate){
if(!this.disabled && this.menu){
clearTimeout(this.hideTimer);
delete this.hideTimer;
if(!this.menu.isVisible() && !this.showTimer){
this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
}else if (this.menu.isVisible() && autoActivate){
this.menu.tryActivate(0, 1);
}
}
},
// private
deferExpand : function(autoActivate){
delete this.showTimer;
this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
if(autoActivate){
this.menu.tryActivate(0, 1);
}
},
// private
hideMenu : function(){
clearTimeout(this.showTimer);
delete this.showTimer;
if(!this.hideTimer && this.menu && this.menu.isVisible()){
this.hideTimer = this.deferHide.defer(this.hideDelay, this);
}
},
// private
deferHide : function(){
delete this.hideTimer;
this.menu.hide();
}
});