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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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")){
102 <div id="method-Ext.menu.MenuMgr-hideAll"></div>/**
103 * Hides all menus that are currently visible
104 * @return {Boolean} success True if any active menus were hidden.
106 hideAll : function(){
111 register : function(menu){
115 menus[menu.id] = menu;
117 beforehide: onBeforeHide,
119 beforeshow: onBeforeShow,
124 <div id="method-Ext.menu.MenuMgr-get"></div>/**
125 * Returns a {@link Ext.menu.Menu} object
126 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
127 * be used to generate and return a new Menu instance.
128 * @return {Ext.menu.Menu} The specified menu, or null if none are found
130 get : function(menu){
131 if(typeof menu == "string"){ // menu id
132 if(!menus){ // not initialized, no menus to return
136 }else if(menu.events){ // menu instance
138 }else if(typeof menu.length == 'number'){ // array of menu items?
139 return new Ext.menu.Menu({items:menu});
140 }else{ // otherwise, must be a config
141 return Ext.create(menu, 'menu');
146 unregister : function(menu){
147 delete menus[menu.id];
148 menu.un("beforehide", onBeforeHide);
149 menu.un("hide", onHide);
150 menu.un("beforeshow", onBeforeShow);
151 menu.un("show", onShow);
155 registerCheckable : function(menuItem){
156 var g = menuItem.group;
161 groups[g].push(menuItem);
166 unregisterCheckable : function(menuItem){
167 var g = menuItem.group;
169 groups[g].remove(menuItem);
174 onCheckChange: function(item, state){
175 if(item.group && state){
176 var group = groups[item.group],
184 current.setChecked(false);
190 getCheckedItem : function(groupId){
191 var g = groups[groupId];
193 for(var i = 0, l = g.length; i < l; i++){
202 setCheckedItem : function(groupId, itemId){
203 var g = groups[groupId];
205 for(var i = 0, l = g.length; i < l; i++){
206 if(g[i].id == itemId){
207 g[i].setChecked(true);