4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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,
123 if (Ext.Date.getElapsed(lastShow) > 50 && active.length > 0 && !e.getTarget('.' + Ext.baseCSSPrefix + 'menu')) {
125 // in IE, if we mousedown on a focusable element, the focus gets cancelled and the focus event is never
126 // fired on the element, so we'll focus it here
127 if (Ext.isIE && Ext.fly(target).focusable()) {
134 register: function(menu) {
142 me.menus[menu.id] = menu;
144 beforehide: me.onBeforeHide,
146 beforeshow: me.onBeforeShow,
153 <span id='Ext-menu-Manager-method-get'> /**
154 </span> * Returns a {@link Ext.menu.Menu} object
155 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
156 * be used to generate and return a new Menu this.
157 * @return {Ext.menu.Menu} The specified menu, or null if none are found
159 get: function(menu) {
160 var menus = this.menus;
162 if (typeof menu == 'string') { // menu id
163 if (!menus) { // not initialized, no menus to return
167 } else if (menu.isMenu) { // menu instance
169 } else if (Ext.isArray(menu)) { // array of menu items
170 return Ext.create('Ext.menu.Menu', {items:menu});
171 } else { // otherwise, must be a config
172 return Ext.ComponentManager.create(menu, 'menu');
177 unregister: function(menu) {
182 delete menus[menu.id];
185 beforehide: me.onBeforeHide,
187 beforeshow: me.onBeforeShow,
194 registerCheckable: function(menuItem) {
195 var groups = this.groups,
196 groupId = menuItem.group;
199 if (!groups[groupId]) {
200 groups[groupId] = [];
203 groups[groupId].push(menuItem);
208 unregisterCheckable: function(menuItem) {
209 var groups = this.groups,
210 groupId = menuItem.group;
213 Ext.Array.remove(groups[groupId], menuItem);
217 onCheckChange: function(menuItem, state) {
218 var groups = this.groups,
219 groupId = menuItem.group,
223 if (groupId && state) {
224 group = groups[groupId];
226 for (; i < ln; i++) {
228 if (curr != menuItem) {
229 curr.setChecked(false);