3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.menu.MenuMgr"></div>/**
16 * @class Ext.menu.MenuMgr
17 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
20 Ext.menu.MenuMgr = function(){
21 var menus, active, groups = {}, attached = false, lastShow = new Date();
23 // private - called when first menu is created
26 active = new Ext.util.MixedCollection();
27 Ext.getDoc().addKeyListener(27, function(){
28 if(active.length > 0){
36 if(active && active.length > 0){
37 var c = active.clone();
49 if(active.length < 1){
50 Ext.getDoc().un("mousedown", onMouseDown);
57 var last = active.last();
58 lastShow = new Date();
61 Ext.getDoc().on("mousedown", onMouseDown);
65 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
66 m.parentMenu.activeChild = m;
67 }else if(last && !last.isDestroyed && last.isVisible()){
68 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
73 function onBeforeHide(m){
78 clearTimeout(m.autoHideTimer);
79 delete m.autoHideTimer;
84 function onBeforeShow(m){
85 var pm = m.parentMenu;
86 if(!pm && !m.allowOtherMenus){
88 }else if(pm && pm.activeChild){
89 pm.activeChild.hide();
94 function onMouseDown(e){
95 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
101 function onBeforeCheck(mi, state){
103 var g = groups[mi.group];
104 for(var i = 0, l = g.length; i < l; i++){
106 g[i].setChecked(false);
114 <div id="method-Ext.menu.MenuMgr-hideAll"></div>/**
115 * Hides all menus that are currently visible
116 * @return {Boolean} success True if any active menus were hidden.
118 hideAll : function(){
123 register : function(menu){
127 menus[menu.id] = menu;
129 beforehide: onBeforeHide,
131 beforeshow: onBeforeShow,
136 <div id="method-Ext.menu.MenuMgr-get"></div>/**
137 * Returns a {@link Ext.menu.Menu} object
138 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
139 * be used to generate and return a new Menu instance.
140 * @return {Ext.menu.Menu} The specified menu, or null if none are found
142 get : function(menu){
143 if(typeof menu == "string"){ // menu id
144 if(!menus){ // not initialized, no menus to return
148 }else if(menu.events){ // menu instance
150 }else if(typeof menu.length == 'number'){ // array of menu items?
151 return new Ext.menu.Menu({items:menu});
152 }else{ // otherwise, must be a config
153 return Ext.create(menu, 'menu');
158 unregister : function(menu){
159 delete menus[menu.id];
160 menu.un("beforehide", onBeforeHide);
161 menu.un("hide", onHide);
162 menu.un("beforeshow", onBeforeShow);
163 menu.un("show", onShow);
167 registerCheckable : function(menuItem){
168 var g = menuItem.group;
173 groups[g].push(menuItem);
174 menuItem.on("beforecheckchange", onBeforeCheck);
179 unregisterCheckable : function(menuItem){
180 var g = menuItem.group;
182 groups[g].remove(menuItem);
183 menuItem.un("beforecheckchange", onBeforeCheck);
187 getCheckedItem : function(groupId){
188 var g = groups[groupId];
190 for(var i = 0, l = g.length; i < l; i++){
199 setCheckedItem : function(groupId, itemId){
200 var g = groups[groupId];
202 for(var i = 0, l = g.length; i < l; i++){
203 if(g[i].id == itemId){
204 g[i].setChecked(true);