3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.menu.MenuMgr"></div>/**
15 * @class Ext.menu.MenuMgr
16 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
19 Ext.menu.MenuMgr = function(){
20 var menus, active, groups = {}, attached = false, lastShow = new Date();
22 // private - called when first menu is created
25 active = new Ext.util.MixedCollection();
26 Ext.getDoc().addKeyListener(27, function(){
27 if(active.length > 0){
35 if(active && active.length > 0){
36 var c = active.clone();
46 if(active.length < 1){
47 Ext.getDoc().un("mousedown", onMouseDown);
54 var last = active.last();
55 lastShow = new Date();
58 Ext.getDoc().on("mousedown", onMouseDown);
62 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
63 m.parentMenu.activeChild = m;
64 }else if(last && last.isVisible()){
65 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
70 function onBeforeHide(m){
75 clearTimeout(m.autoHideTimer);
76 delete m.autoHideTimer;
81 function onBeforeShow(m){
82 var pm = m.parentMenu;
83 if(!pm && !m.allowOtherMenus){
85 }else if(pm && pm.activeChild){
86 pm.activeChild.hide();
91 function onMouseDown(e){
92 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
98 function onBeforeCheck(mi, state){
100 var g = groups[mi.group];
101 for(var i = 0, l = g.length; i < l; i++){
103 g[i].setChecked(false);
111 <div id="method-Ext.menu.MenuMgr-hideAll"></div>/**
112 * Hides all menus that are currently visible
114 hideAll : function(){
119 register : function(menu){
123 menus[menu.id] = menu;
124 menu.on("beforehide", onBeforeHide);
125 menu.on("hide", onHide);
126 menu.on("beforeshow", onBeforeShow);
127 menu.on("show", onShow);
129 if(g && menu.events["checkchange"]){
133 groups[g].push(menu);
134 menu.on("checkchange", onCheck);
138 <div id="method-Ext.menu.MenuMgr-get"></div>/**
139 * Returns a {@link Ext.menu.Menu} object
140 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
141 * be used to generate and return a new Menu instance.
142 * @return {Ext.menu.Menu} The specified menu, or null if none are found
144 get : function(menu){
145 if(typeof menu == "string"){ // menu id
146 if(!menus){ // not initialized, no menus to return
150 }else if(menu.events){ // menu instance
152 }else if(typeof menu.length == 'number'){ // array of menu items?
153 return new Ext.menu.Menu({items:menu});
154 }else{ // otherwise, must be a config
155 return Ext.create(menu, 'menu');
160 unregister : function(menu){
161 delete menus[menu.id];
162 menu.un("beforehide", onBeforeHide);
163 menu.un("hide", onHide);
164 menu.un("beforeshow", onBeforeShow);
165 menu.un("show", onShow);
167 if(g && menu.events["checkchange"]){
168 groups[g].remove(menu);
169 menu.un("checkchange", onCheck);
174 registerCheckable : function(menuItem){
175 var g = menuItem.group;
180 groups[g].push(menuItem);
181 menuItem.on("beforecheckchange", onBeforeCheck);
186 unregisterCheckable : function(menuItem){
187 var g = menuItem.group;
189 groups[g].remove(menuItem);
190 menuItem.un("beforecheckchange", onBeforeCheck);
194 getCheckedItem : function(groupId){
195 var g = groups[groupId];
197 for(var i = 0, l = g.length; i < l; i++){
206 setCheckedItem : function(groupId, itemId){
207 var g = groups[groupId];
209 for(var i = 0, l = g.length; i < l; i++){
210 if(g[i].id == itemId){
211 g[i].setChecked(true);