StartMenu.js
6.75 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*!
* Ext JS Library 3.3.1
* Copyright(c) 2006-2010 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
/**
* @class Ext.ux.StartMenu
* @extends Ext.menu.Menu
* A start menu object.
* @constructor
* Creates a new StartMenu
* @param {Object} config Configuration options
*
* SAMPLE USAGE:
*
* this.startMenu = new Ext.ux.StartMenu({
* iconCls: 'user',
* height: 300,
* shadow: true,
* title: get_cookie('memberName'),
* width: 300
* });
*
* this.startMenu.add({
* text: 'Grid Window',
* iconCls:'icon-grid',
* handler : this.createWindow,
* scope: this
* });
*
* this.startMenu.addTool({
* text:'Logout',
* iconCls:'logout',
* handler:function(){ window.location = "logout.php"; },
* scope:this
* });
*/
Ext.namespace("Ext.ux");
Ext.ux.StartMenu = Ext.extend(Ext.menu.Menu, {
initComponent: function(config) {
Ext.ux.StartMenu.superclass.initComponent.call(this, config);
var tools = this.toolItems;
this.toolItems = new Ext.util.MixedCollection();
if(tools){
this.addTool.apply(this, tools);
}
},
// private
onRender : function(ct, position){
Ext.ux.StartMenu.superclass.onRender.call(this, ct, position);
var el = this.el.addClass('ux-start-menu');
var header = el.createChild({
tag: "div",
cls: "x-window-header x-unselectable x-panel-icon "+this.iconCls
});
this.header = header;
var headerText = header.createChild({
tag: "span",
cls: "x-window-header-text"
});
var tl = header.wrap({
cls: "ux-start-menu-tl"
});
var tr = header.wrap({
cls: "ux-start-menu-tr"
});
var tc = header.wrap({
cls: "ux-start-menu-tc"
});
this.menuBWrap = el.createChild({
tag: "div",
cls: "x-window-body x-border-layout-ct ux-start-menu-body"
});
var ml = this.menuBWrap.wrap({
cls: "ux-start-menu-ml"
});
var mc = this.menuBWrap.wrap({
cls: "x-window-mc ux-start-menu-bwrap"
});
this.menuPanel = this.menuBWrap.createChild({
tag: "div",
cls: "x-panel x-border-panel ux-start-menu-apps-panel"
});
this.toolsPanel = this.menuBWrap.createChild({
tag: "div",
cls: "x-panel x-border-panel ux-start-menu-tools-panel"
});
var bwrap = ml.wrap({cls: "x-window-bwrap"});
var bc = bwrap.createChild({
tag: "div",
cls: "ux-start-menu-bc"
});
var bl = bc.wrap({
cls: "ux-start-menu-bl x-panel-nofooter"
});
var br = bc.wrap({
cls: "ux-start-menu-br"
});
this.ul.appendTo(this.menuPanel);
var toolsUl = this.toolsPanel.createChild({
tag: "ul",
cls: "x-menu-list"
});
this.mon(toolsUl, 'click', this.onClick, this);
this.mon(toolsUl, 'mouseover', this.onMouseOver, this);
this.mon(toolsUl, 'mouseout', this.onMouseOut, this);
this.items.each(function(item){
item.parentMenu = this;
}, this);
this.toolItems.each(
function(item){
var li = document.createElement("li");
li.className = "x-menu-list-item";
toolsUl.dom.appendChild(li);
item.render(li);
item.parentMenu = this;
}, this);
this.toolsUl = toolsUl;
this.menuBWrap.setStyle('position', 'relative');
this.menuBWrap.setHeight(this.height - 28);
this.menuPanel.setStyle({
padding: '2px',
position: 'absolute',
overflow: 'auto'
});
this.toolsPanel.setStyle({
padding: '2px 4px 2px 2px',
position: 'absolute',
overflow: 'auto'
});
this.setTitle(this.title);
},
// private
findTargetItem : function(e){
var t = e.getTarget(".x-menu-list-item", this.ul, true);
if(t && t.menuItemId){
if(this.items.get(t.menuItemId)){
return this.items.get(t.menuItemId);
}else{
return this.toolItems.get(t.menuItemId);
}
}
},
/**
* Displays this menu relative to another element
* @param {Mixed} element The element to align to
* @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
* the element (defaults to this.defaultAlign)
* @param {Ext.ux.StartMenu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
*/
show : function(el, pos, parentMenu){
this.parentMenu = parentMenu;
if(!this.el){
this.render();
}
this.fireEvent("beforeshow", this);
this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
var tPanelWidth = 100;
var box = this.menuBWrap.getBox();
this.menuPanel.setWidth(box.width-tPanelWidth);
this.menuPanel.setHeight(box.height);
this.toolsPanel.setWidth(tPanelWidth);
this.toolsPanel.setX(box.x+box.width-tPanelWidth);
this.toolsPanel.setHeight(box.height);
},
addTool : function(){
var a = arguments, l = a.length, item;
for(var i = 0; i < l; i++){
var el = a[i];
if(el.render){ // some kind of Item
item = this.addToolItem(el);
}else if(typeof el == "string"){ // string
if(el == "separator" || el == "-"){
item = this.addToolSeparator();
}else{
item = this.addText(el);
}
}else if(el.tagName || el.el){ // element
item = this.addElement(el);
}else if(typeof el == "object"){ // must be menu item config?
item = this.addToolMenuItem(el);
}
}
return item;
},
/**
* Adds a separator bar to the Tools
* @return {Ext.menu.Item} The menu item that was added
*/
addToolSeparator : function(){
return this.addToolItem(new Ext.menu.Separator({itemCls: 'ux-toolmenu-sep'}));
},
addToolItem : function(item){
this.toolItems.add(item);
if(this.ul){
var li = document.createElement("li");
li.className = "x-menu-list-item";
this.ul.dom.appendChild(li);
item.render(li, this);
this.delayAutoWidth();
}
return item;
},
addToolMenuItem : function(config){
if(!(config instanceof Ext.menu.Item)){
if(typeof config.checked == "boolean"){ // must be check menu item config?
config = new Ext.menu.CheckItem(config);
}else{
config = new Ext.menu.Item(config);
}
}
return this.addToolItem(config);
},
setTitle : function(title, iconCls){
this.title = title;
this.header.child('span').update(title);
return this;
}
});