3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * Ext JS Library 3.3.1
17 * Copyright(c) 2006-2010 Sencha Inc.
18 * licensing@sencha.com
19 * http://www.sencha.com/license
22 * @class Ext.ux.StartMenu
23 * @extends Ext.menu.Menu
24 * A start menu object.
26 * Creates a new StartMenu
27 * @param {Object} config Configuration options
31 * this.startMenu = new Ext.ux.StartMenu({
35 * title: get_cookie('memberName'),
39 * this.startMenu.add({
40 * text: 'Grid Window',
41 * iconCls:'icon-grid',
42 * handler : this.createWindow,
46 * this.startMenu.addTool({
49 * handler:function(){ window.location = "logout.php"; },
54 Ext.namespace("Ext.ux");
56 Ext.ux.StartMenu = Ext.extend(Ext.menu.Menu, {
57 initComponent: function(config) {
58 Ext.ux.StartMenu.superclass.initComponent.call(this, config);
60 var tools = this.toolItems;
61 this.toolItems = new Ext.util.MixedCollection();
63 this.addTool.apply(this, tools);
68 onRender : function(ct, position){
69 Ext.ux.StartMenu.superclass.onRender.call(this, ct, position);
70 var el = this.el.addClass('ux-start-menu');
72 var header = el.createChild({
74 cls: "x-window-header x-unselectable x-panel-icon "+this.iconCls
79 var headerText = header.createChild({
81 cls: "x-window-header-text"
83 var tl = header.wrap({
84 cls: "ux-start-menu-tl"
86 var tr = header.wrap({
87 cls: "ux-start-menu-tr"
89 var tc = header.wrap({
90 cls: "ux-start-menu-tc"
93 this.menuBWrap = el.createChild({
95 cls: "x-window-body x-border-layout-ct ux-start-menu-body"
97 var ml = this.menuBWrap.wrap({
98 cls: "ux-start-menu-ml"
100 var mc = this.menuBWrap.wrap({
101 cls: "x-window-mc ux-start-menu-bwrap"
104 this.menuPanel = this.menuBWrap.createChild({
106 cls: "x-panel x-border-panel ux-start-menu-apps-panel"
108 this.toolsPanel = this.menuBWrap.createChild({
110 cls: "x-panel x-border-panel ux-start-menu-tools-panel"
113 var bwrap = ml.wrap({cls: "x-window-bwrap"});
114 var bc = bwrap.createChild({
116 cls: "ux-start-menu-bc"
119 cls: "ux-start-menu-bl x-panel-nofooter"
122 cls: "ux-start-menu-br"
125 this.ul.appendTo(this.menuPanel);
127 var toolsUl = this.toolsPanel.createChild({
132 this.mon(toolsUl, 'click', this.onClick, this);
133 this.mon(toolsUl, 'mouseover', this.onMouseOver, this);
134 this.mon(toolsUl, 'mouseout', this.onMouseOut, this);
136 this.items.each(function(item){
137 item.parentMenu = this;
142 var li = document.createElement("li");
143 li.className = "x-menu-list-item";
144 toolsUl.dom.appendChild(li);
146 item.parentMenu = this;
149 this.toolsUl = toolsUl;
151 this.menuBWrap.setStyle('position', 'relative');
152 this.menuBWrap.setHeight(this.height - 28);
154 this.menuPanel.setStyle({
156 position: 'absolute',
160 this.toolsPanel.setStyle({
161 padding: '2px 4px 2px 2px',
162 position: 'absolute',
166 this.setTitle(this.title);
170 findTargetItem : function(e){
171 var t = e.getTarget(".x-menu-list-item", this.ul, true);
172 if(t && t.menuItemId){
173 if(this.items.get(t.menuItemId)){
174 return this.items.get(t.menuItemId);
176 return this.toolItems.get(t.menuItemId);
182 * Displays this menu relative to another element
183 * @param {Mixed} element The element to align to
184 * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
185 * the element (defaults to this.defaultAlign)
186 * @param {Ext.ux.StartMenu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
188 show : function(el, pos, parentMenu){
189 this.parentMenu = parentMenu;
194 this.fireEvent("beforeshow", this);
195 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
196 var tPanelWidth = 100;
197 var box = this.menuBWrap.getBox();
198 this.menuPanel.setWidth(box.width-tPanelWidth);
199 this.menuPanel.setHeight(box.height);
201 this.toolsPanel.setWidth(tPanelWidth);
202 this.toolsPanel.setX(box.x+box.width-tPanelWidth);
203 this.toolsPanel.setHeight(box.height);
206 addTool : function(){
207 var a = arguments, l = a.length, item;
208 for(var i = 0; i < l; i++){
210 if(el.render){ // some kind of Item
211 item = this.addToolItem(el);
212 }else if(typeof el == "string"){ // string
213 if(el == "separator" || el == "-"){
214 item = this.addToolSeparator();
216 item = this.addText(el);
218 }else if(el.tagName || el.el){ // element
219 item = this.addElement(el);
220 }else if(typeof el == "object"){ // must be menu item config?
221 item = this.addToolMenuItem(el);
228 * Adds a separator bar to the Tools
229 * @return {Ext.menu.Item} The menu item that was added
231 addToolSeparator : function(){
232 return this.addToolItem(new Ext.menu.Separator({itemCls: 'ux-toolmenu-sep'}));
235 addToolItem : function(item){
236 this.toolItems.add(item);
238 var li = document.createElement("li");
239 li.className = "x-menu-list-item";
240 this.ul.dom.appendChild(li);
241 item.render(li, this);
242 this.delayAutoWidth();
247 addToolMenuItem : function(config){
248 if(!(config instanceof Ext.menu.Item)){
249 if(typeof config.checked == "boolean"){ // must be check menu item config?
250 config = new Ext.menu.CheckItem(config);
252 config = new Ext.menu.Item(config);
255 return this.addToolItem(config);
258 setTitle : function(title, iconCls){
260 this.header.child('span').update(title);