4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.bootstrap.MenuMgr
14 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
17 Roo.bootstrap.MenuMgr = function(){
18 var menus, active, groups = {}, attached = false, lastShow = new Date();
20 // private - called when first menu is created
23 active = new Roo.util.MixedCollection();
24 Roo.get(document).addKeyListener(27, function(){
25 if(active.length > 0){
33 if(active && active.length > 0){
34 var c = active.clone();
44 if(active.length < 1){
45 Roo.get(document).un("mousedown", onMouseDown);
46 Roo.select('iframe').un("mousedown", onMouseDown);
53 var last = active.last();
54 lastShow = new Date();
57 Roo.get(document).on("mousedown", onMouseDown);
58 Roo.select('iframe').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 && active != m){
86 pm.activeChild.hide();
91 function onMouseDown(e){
92 //Roo.log("on MouseDown");
93 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
99 function onBeforeCheck(mi, state){
101 var g = groups[mi.group];
102 for(var i = 0, l = g.length; i < l; i++){
104 g[i].setChecked(false);
113 * Hides all menus that are currently visible
115 hideAll : function(){
120 register : function(menu){
124 menus[menu.id] = menu;
125 menu.on("beforehide", onBeforeHide);
126 menu.on("hide", onHide);
127 menu.on("beforeshow", onBeforeShow);
128 menu.on("show", onShow);
130 if(g && menu.events["checkchange"]){
134 groups[g].push(menu);
135 menu.on("checkchange", onCheck);
140 * Returns a {@link Roo.menu.Menu} object
141 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
142 * be used to generate and return a new Menu instance.
144 get : function(menu){
145 if(typeof menu == "string"){ // menu id
147 }else if(menu.events){ // menu instance
150 /*else if(typeof menu.length == 'number'){ // array of menu items?
151 return new Roo.bootstrap.Menu({items:menu});
152 }else{ // otherwise, must be a config
153 return new Roo.bootstrap.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);