4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-menu-Manager'>/**
19 </span> * @class Ext.menu.Manager
20 * Provides a common registry of all menus on a page.
23 Ext.define('Ext.menu.Manager', {
26 'Ext.util.MixedCollection',
29 alternateClassName: 'Ext.menu.MenuMgr',
31 uses: ['Ext.menu.Menu'],
41 me.active = Ext.create('Ext.util.MixedCollection');
42 Ext.getDoc().addKeyListener(27, function() {
43 if (me.active.length > 0) {
49 <span id='Ext-menu-Manager-method-hideAll'> /**
50 </span> * Hides all menus that are currently visible
51 * @return {Boolean} success True if any active menus were hidden.
54 var active = this.active,
56 if (active && active.length > 0) {
70 if (active.length < 1) {
71 Ext.getDoc().un('mousedown', me.onMouseDown, me);
80 attached = me.attached,
84 me.lastShow = new Date();
87 Ext.getDoc().on('mousedown', me.onMouseDown, me);
93 onBeforeHide: function(m) {
97 if (m.autoHideTimer) {
98 clearTimeout(m.autoHideTimer);
99 delete m.autoHideTimer;
103 onBeforeShow: function(m) {
104 var active = this.active,
105 parentMenu = m.parentMenu;
108 if (!parentMenu && !m.allowOtherMenus) {
111 else if (parentMenu && parentMenu.activeChild && m != parentMenu.activeChild) {
112 parentMenu.activeChild.hide();
117 onMouseDown: function(e) {
120 lastShow = me.lastShow;
122 if (Ext.Date.getElapsed(lastShow) > 50 && active.length > 0 && !e.getTarget('.' + Ext.baseCSSPrefix + 'menu')) {
128 register: function(menu) {
136 me.menus[menu.id] = menu;
138 beforehide: me.onBeforeHide,
140 beforeshow: me.onBeforeShow,
147 <span id='Ext-menu-Manager-method-get'> /**
148 </span> * Returns a {@link Ext.menu.Menu} object
149 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
150 * be used to generate and return a new Menu this.
151 * @return {Ext.menu.Menu} The specified menu, or null if none are found
153 get: function(menu) {
154 var menus = this.menus;
156 if (typeof menu == 'string') { // menu id
157 if (!menus) { // not initialized, no menus to return
161 } else if (menu.isMenu) { // menu instance
163 } else if (Ext.isArray(menu)) { // array of menu items
164 return Ext.create('Ext.menu.Menu', {items:menu});
165 } else { // otherwise, must be a config
166 return Ext.ComponentManager.create(menu, 'menu');
171 unregister: function(menu) {
176 delete menus[menu.id];
179 beforehide: me.onBeforeHide,
181 beforeshow: me.onBeforeShow,
188 registerCheckable: function(menuItem) {
189 var groups = this.groups,
190 groupId = menuItem.group;
193 if (!groups[groupId]) {
194 groups[groupId] = [];
197 groups[groupId].push(menuItem);
202 unregisterCheckable: function(menuItem) {
203 var groups = this.groups,
204 groupId = menuItem.group;
207 Ext.Array.remove(groups[groupId], menuItem);
211 onCheckChange: function(menuItem, state) {
212 var groups = this.groups,
213 groupId = menuItem.group,
217 if (groupId && state) {
218 group = groups[groupId];
220 for (; i < ln; i++) {
222 if (curr != menuItem) {
223 curr.setChecked(false);