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 * @class Ext.menu.Manager
17 * Provides a common registry of all menus on a page.
20 Ext.define('Ext.menu.Manager', {
23 'Ext.util.MixedCollection',
26 alternateClassName: 'Ext.menu.MenuMgr',
28 uses: ['Ext.menu.Menu'],
38 me.active = Ext.create('Ext.util.MixedCollection');
39 Ext.getDoc().addKeyListener(27, function() {
40 if (me.active.length > 0) {
47 * Hides all menus that are currently visible
48 * @return {Boolean} success True if any active menus were hidden.
51 var active = this.active,
53 if (active && active.length > 0) {
67 if (active.length < 1) {
68 Ext.getDoc().un('mousedown', me.onMouseDown, me);
77 attached = me.attached,
81 me.lastShow = new Date();
84 Ext.getDoc().on('mousedown', me.onMouseDown, me);
90 onBeforeHide: function(m) {
94 if (m.autoHideTimer) {
95 clearTimeout(m.autoHideTimer);
96 delete m.autoHideTimer;
100 onBeforeShow: function(m) {
101 var active = this.active,
102 parentMenu = m.parentMenu;
105 if (!parentMenu && !m.allowOtherMenus) {
108 else if (parentMenu && parentMenu.activeChild && m != parentMenu.activeChild) {
109 parentMenu.activeChild.hide();
114 onMouseDown: function(e) {
117 lastShow = me.lastShow,
120 if (Ext.Date.getElapsed(lastShow) > 50 && active.length > 0 && !e.getTarget('.' + Ext.baseCSSPrefix + 'menu')) {
122 // in IE, if we mousedown on a focusable element, the focus gets cancelled and the focus event is never
123 // fired on the element, so we'll focus it here
124 if (Ext.isIE && Ext.fly(target).focusable()) {
131 register: function(menu) {
139 me.menus[menu.id] = menu;
141 beforehide: me.onBeforeHide,
143 beforeshow: me.onBeforeShow,
151 * Returns a {@link Ext.menu.Menu} object
152 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
153 * be used to generate and return a new Menu this.
154 * @return {Ext.menu.Menu} The specified menu, or null if none are found
156 get: function(menu) {
157 var menus = this.menus;
159 if (typeof menu == 'string') { // menu id
160 if (!menus) { // not initialized, no menus to return
164 } else if (menu.isMenu) { // menu instance
166 } else if (Ext.isArray(menu)) { // array of menu items
167 return Ext.create('Ext.menu.Menu', {items:menu});
168 } else { // otherwise, must be a config
169 return Ext.ComponentManager.create(menu, 'menu');
174 unregister: function(menu) {
179 delete menus[menu.id];
182 beforehide: me.onBeforeHide,
184 beforeshow: me.onBeforeShow,
191 registerCheckable: function(menuItem) {
192 var groups = this.groups,
193 groupId = menuItem.group;
196 if (!groups[groupId]) {
197 groups[groupId] = [];
200 groups[groupId].push(menuItem);
205 unregisterCheckable: function(menuItem) {
206 var groups = this.groups,
207 groupId = menuItem.group;
210 Ext.Array.remove(groups[groupId], menuItem);
214 onCheckChange: function(menuItem, state) {
215 var groups = this.groups,
216 groupId = menuItem.group,
220 if (groupId && state) {
221 group = groups[groupId];
223 for (; i < ln; i++) {
225 if (curr != menuItem) {
226 curr.setChecked(false);