176 lines
No EOL
5.7 KiB
HTML
176 lines
No EOL
5.7 KiB
HTML
<html><head><title>MenuMgr.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>MenuMgr.js</h1><pre class="highlighted"><code><i>/**
|
|
* @class Ext.menu.MenuMgr
|
|
* Provides a common registry of all menu items on a page so that they can be easily accessed by id.
|
|
* @singleton
|
|
*/</i>
|
|
Ext.menu.MenuMgr = <b>function</b>(){
|
|
<b>var</b> menus, active, groups = {}, attached = false, lastShow = <b>new</b> Date();
|
|
|
|
<i>// private - called when first menu is created</i>
|
|
<b>function</b> init(){
|
|
menus = {}, active = <b>new</b> Ext.util.MixedCollection();
|
|
Ext.get(document).addKeyListener(27, <b>function</b>(){
|
|
<b>if</b>(active.length > 0){
|
|
hideAll();
|
|
}
|
|
});
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> hideAll(){
|
|
<b>if</b>(active.length > 0){
|
|
<b>var</b> c = active.clone();
|
|
c.each(<b>function</b>(m){
|
|
m.hide();
|
|
});
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onHide(m){
|
|
active.remove(m);
|
|
<b>if</b>(active.length < 1){
|
|
Ext.get(document).un("mousedown", onMouseDown);
|
|
attached = false;
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onShow(m){
|
|
<b>var</b> last = active.last();
|
|
lastShow = <b>new</b> Date();
|
|
active.add(m);
|
|
<b>if</b>(!attached){
|
|
Ext.get(document).on("mousedown", onMouseDown);
|
|
attached = true;
|
|
}
|
|
<b>if</b>(m.parentMenu){
|
|
m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
|
|
m.parentMenu.activeChild = m;
|
|
}<b>else</b> if(last && last.isVisible()){
|
|
m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onBeforeHide(m){
|
|
<b>if</b>(m.activeChild){
|
|
m.activeChild.hide();
|
|
}
|
|
<b>if</b>(m.autoHideTimer){
|
|
clearTimeout(m.autoHideTimer);
|
|
<b>delete</b> m.autoHideTimer;
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onBeforeShow(m){
|
|
<b>var</b> pm = m.parentMenu;
|
|
<b>if</b>(!pm && !m.allowOtherMenus){
|
|
hideAll();
|
|
}<b>else</b> if(pm && pm.activeChild){
|
|
pm.activeChild.hide();
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onMouseDown(e){
|
|
<b>if</b>(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
|
|
hideAll();
|
|
}
|
|
}
|
|
|
|
<i>// private</i>
|
|
<b>function</b> onBeforeCheck(mi, state){
|
|
<b>if</b>(state){
|
|
<b>var</b> g = groups[mi.group];
|
|
<b>for</b>(var i = 0, l = g.length; i < l; i++){
|
|
<b>if</b>(g[i] != mi){
|
|
g[i].setChecked(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
<b>return</b> {
|
|
|
|
<i>/**
|
|
* Hides all menus that are currently visible
|
|
*/</i>
|
|
hideAll : <b>function</b>(){
|
|
hideAll();
|
|
},
|
|
|
|
<i>// private</i>
|
|
register : <b>function</b>(menu){
|
|
<b>if</b>(!menus){
|
|
init();
|
|
}
|
|
menus[menu.id] = menu;
|
|
menu.on("beforehide", onBeforeHide);
|
|
menu.on("hide", onHide);
|
|
menu.on("beforeshow", onBeforeShow);
|
|
menu.on("show", onShow);
|
|
<b>var</b> g = menu.group;
|
|
<b>if</b>(g && menu.events["checkchange"]){
|
|
<b>if</b>(!groups[g]){
|
|
groups[g] = [];
|
|
}
|
|
groups[g].push(menu);
|
|
menu.on("checkchange", onCheck);
|
|
}
|
|
},
|
|
|
|
<i>/**
|
|
* Returns a {@link Ext.menu.Menu} object
|
|
* @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
|
|
* be used to generate and <b>return</b> a <b>new</b> Menu instance.
|
|
*/</i>
|
|
get : <b>function</b>(menu){
|
|
<b>if</b>(typeof menu == "string"){ <i>// menu id</i>
|
|
<b>return</b> menus[menu];
|
|
}<b>else</b> if(menu.events){ <i>// menu instance</i>
|
|
<b>return</b> menu;
|
|
}<b>else</b>{ <i>// otherwise, must be a config</i>
|
|
<b>return</b> new Ext.menu.Menu(menu);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
unregister : <b>function</b>(menu){
|
|
<b>delete</b> menus[menu.id];
|
|
menu.un("beforehide", onBeforeHide);
|
|
menu.un("hide", onHide);
|
|
menu.un("beforeshow", onBeforeShow);
|
|
menu.un("show", onShow);
|
|
<b>var</b> g = menu.group;
|
|
<b>if</b>(g && menu.events["checkchange"]){
|
|
groups[g].remove(menu);
|
|
menu.un("checkchange", onCheck);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
registerCheckable : <b>function</b>(menuItem){
|
|
<b>var</b> g = menuItem.group;
|
|
<b>if</b>(g){
|
|
<b>if</b>(!groups[g]){
|
|
groups[g] = [];
|
|
}
|
|
groups[g].push(menuItem);
|
|
menuItem.on("beforecheckchange", onBeforeCheck);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
unregisterCheckable : <b>function</b>(menuItem){
|
|
<b>var</b> g = menuItem.group;
|
|
<b>if</b>(g){
|
|
groups[g].remove(menuItem);
|
|
menuItem.un("beforecheckchange", onBeforeCheck);
|
|
}
|
|
}
|
|
};
|
|
}();
|
|
</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |