StartMenu.js
2.39 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
/*!
* Ext JS Library 4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
Ext.define('Ext.ux.desktop.StartMenu', {
extend: 'Ext.panel.Panel',
requires: [
'Ext.menu.Menu',
'Ext.toolbar.Toolbar'
],
ariaRole: 'menu',
cls: 'x-menu ux-start-menu',
defaultAlign: 'bl-tl',
iconCls: 'user',
floating: true,
shadow: true,
// We have to hardcode a width because the internal Menu cannot drive our width.
// This is combined with changing the align property of the menu's layout from the
// typical 'stretchmax' to 'stretch' which allows the the items to fill the menu
// area.
width: 300,
initComponent: function() {
var me = this, menu = me.menu;
me.menu = new Ext.menu.Menu({
cls: 'ux-start-menu-body',
border: false,
floating: false,
items: menu
});
me.menu.layout.align = 'stretch';
me.items = [me.menu];
me.layout = 'fit';
Ext.menu.Manager.register(me);
me.callParent();
// TODO - relay menu events
me.toolbar = new Ext.toolbar.Toolbar(Ext.apply({
dock: 'right',
cls: 'ux-start-menu-toolbar',
vertical: true,
width: 100
}, me.toolConfig));
me.toolbar.layout.align = 'stretch';
me.addDocked(me.toolbar);
delete me.toolItems;
me.on('deactivate', function () {
me.hide();
});
},
addMenuItem: function() {
var cmp = this.menu;
cmp.add.apply(cmp, arguments);
},
addToolItem: function() {
var cmp = this.toolbar;
cmp.add.apply(cmp, arguments);
},
showBy: function(cmp, pos, off) {
var me = this;
if (me.floating && cmp) {
me.layout.autoSize = true;
me.show();
// Component or Element
cmp = cmp.el || cmp;
// Convert absolute to floatParent-relative coordinates if necessary.
var xy = me.el.getAlignToXY(cmp, pos || me.defaultAlign, off);
if (me.floatParent) {
var r = me.floatParent.getTargetEl().getViewRegion();
xy[0] -= r.x;
xy[1] -= r.y;
}
me.showAt(xy);
me.doConstrain();
}
return me;
}
}); // StartMenu