3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.menu.MenuMgr"></div>/**
9 * @class Ext.menu.MenuMgr
10 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
13 Ext.menu.MenuMgr = function(){
14 var menus, active, groups = {}, attached = false, lastShow = new Date();
16 // private - called when first menu is created
19 active = new Ext.util.MixedCollection();
20 Ext.getDoc().addKeyListener(27, function(){
21 if(active.length > 0){
29 if(active && active.length > 0){
30 var c = active.clone();
40 if(active.length < 1){
41 Ext.getDoc().un("mousedown", onMouseDown);
48 var last = active.last();
49 lastShow = new Date();
52 Ext.getDoc().on("mousedown", onMouseDown);
56 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
57 m.parentMenu.activeChild = m;
58 }else if(last && last.isVisible()){
59 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
64 function onBeforeHide(m){
69 clearTimeout(m.autoHideTimer);
70 delete m.autoHideTimer;
75 function onBeforeShow(m){
76 var pm = m.parentMenu;
77 if(!pm && !m.allowOtherMenus){
79 }else if(pm && pm.activeChild){
80 pm.activeChild.hide();
85 function onMouseDown(e){
86 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
92 function onBeforeCheck(mi, state){
94 var g = groups[mi.group];
95 for(var i = 0, l = g.length; i < l; i++){
97 g[i].setChecked(false);
105 <div id="method-Ext.menu.MenuMgr-hideAll"></div>/**
106 * Hides all menus that are currently visible
108 hideAll : function(){
113 register : function(menu){
117 menus[menu.id] = menu;
118 menu.on("beforehide", onBeforeHide);
119 menu.on("hide", onHide);
120 menu.on("beforeshow", onBeforeShow);
121 menu.on("show", onShow);
123 if(g && menu.events["checkchange"]){
127 groups[g].push(menu);
128 menu.on("checkchange", onCheck);
132 <div id="method-Ext.menu.MenuMgr-get"></div>/**
133 * Returns a {@link Ext.menu.Menu} object
134 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
135 * be used to generate and return a new Menu instance.
136 * @return {Ext.menu.Menu} The specified menu, or null if none are found
138 get : function(menu){
139 if(typeof menu == "string"){ // menu id
140 if(!menus){ // not initialized, no menus to return
144 }else if(menu.events){ // menu instance
146 }else if(typeof menu.length == 'number'){ // array of menu items?
147 return new Ext.menu.Menu({items:menu});
148 }else{ // otherwise, must be a config
149 return Ext.create(menu, 'menu');
154 unregister : function(menu){
155 delete menus[menu.id];
156 menu.un("beforehide", onBeforeHide);
157 menu.un("hide", onHide);
158 menu.un("beforeshow", onBeforeShow);
159 menu.un("show", onShow);
161 if(g && menu.events["checkchange"]){
162 groups[g].remove(menu);
163 menu.un("checkchange", onCheck);
168 registerCheckable : function(menuItem){
169 var g = menuItem.group;
174 groups[g].push(menuItem);
175 menuItem.on("beforecheckchange", onBeforeCheck);
180 unregisterCheckable : function(menuItem){
181 var g = menuItem.group;
183 groups[g].remove(menuItem);
184 menuItem.un("beforecheckchange", onBeforeCheck);
188 getCheckedItem : function(groupId){
189 var g = groups[groupId];
191 for(var i = 0, l = g.length; i < l; i++){
200 setCheckedItem : function(groupId, itemId){
201 var g = groups[groupId];
203 for(var i = 0, l = g.length; i < l; i++){
204 if(g[i].id == itemId){
205 g[i].setChecked(true);