3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.menu.MenuMgr"></div>/**
10 * @class Ext.menu.MenuMgr
11 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
14 Ext.menu.MenuMgr = function(){
15 var menus, active, groups = {}, attached = false, lastShow = new Date();
17 // private - called when first menu is created
20 active = new Ext.util.MixedCollection();
21 Ext.getDoc().addKeyListener(27, function(){
22 if(active.length > 0){
30 if(active && active.length > 0){
31 var c = active.clone();
43 if(active.length < 1){
44 Ext.getDoc().un("mousedown", onMouseDown);
51 var last = active.last();
52 lastShow = new Date();
55 Ext.getDoc().on("mousedown", onMouseDown);
59 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
60 m.parentMenu.activeChild = m;
61 }else if(last && !last.isDestroyed && last.isVisible()){
62 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
67 function onBeforeHide(m){
72 clearTimeout(m.autoHideTimer);
73 delete m.autoHideTimer;
78 function onBeforeShow(m){
79 var pm = m.parentMenu;
80 if(!pm && !m.allowOtherMenus){
82 }else if(pm && pm.activeChild){
83 pm.activeChild.hide();
88 function onMouseDown(e){
89 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
95 function onBeforeCheck(mi, state){
97 var g = groups[mi.group];
98 for(var i = 0, l = g.length; i < l; i++){
100 g[i].setChecked(false);
108 <div id="method-Ext.menu.MenuMgr-hideAll"></div>/**
109 * Hides all menus that are currently visible
110 * @return {Boolean} success True if any active menus were hidden.
112 hideAll : function(){
117 register : function(menu){
121 menus[menu.id] = menu;
123 beforehide: onBeforeHide,
125 beforeshow: onBeforeShow,
130 <div id="method-Ext.menu.MenuMgr-get"></div>/**
131 * Returns a {@link Ext.menu.Menu} object
132 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
133 * be used to generate and return a new Menu instance.
134 * @return {Ext.menu.Menu} The specified menu, or null if none are found
136 get : function(menu){
137 if(typeof menu == "string"){ // menu id
138 if(!menus){ // not initialized, no menus to return
142 }else if(menu.events){ // menu instance
144 }else if(typeof menu.length == 'number'){ // array of menu items?
145 return new Ext.menu.Menu({items:menu});
146 }else{ // otherwise, must be a config
147 return Ext.create(menu, 'menu');
152 unregister : function(menu){
153 delete menus[menu.id];
154 menu.un("beforehide", onBeforeHide);
155 menu.un("hide", onHide);
156 menu.un("beforeshow", onBeforeShow);
157 menu.un("show", onShow);
161 registerCheckable : function(menuItem){
162 var g = menuItem.group;
167 groups[g].push(menuItem);
168 menuItem.on("beforecheckchange", onBeforeCheck);
173 unregisterCheckable : function(menuItem){
174 var g = menuItem.group;
176 groups[g].remove(menuItem);
177 menuItem.un("beforecheckchange", onBeforeCheck);
181 getCheckedItem : function(groupId){
182 var g = groups[groupId];
184 for(var i = 0, l = g.length; i < l; i++){
193 setCheckedItem : function(groupId, itemId){
194 var g = groups[groupId];
196 for(var i = 0, l = g.length; i < l; i++){
197 if(g[i].id == itemId){
198 g[i].setChecked(true);