tvheadend/vendor/ext-3.4.1/docs/source/MenuMgr.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

225 lines
6.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-menu-MenuMgr'>/**
</span> * @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
*/
Ext.menu.MenuMgr = function(){
var menus,
active,
map,
groups = {},
attached = false,
lastShow = new Date();
// private - called when first menu is created
function init(){
menus = {};
active = new Ext.util.MixedCollection();
map = Ext.getDoc().addKeyListener(27, hideAll);
map.disable();
}
// private
function hideAll(){
if(active &amp;&amp; active.length &gt; 0){
var c = active.clone();
c.each(function(m){
m.hide();
});
return true;
}
return false;
}
// private
function onHide(m){
active.remove(m);
if(active.length &lt; 1){
map.disable();
Ext.getDoc().un(&quot;mousedown&quot;, onMouseDown);
attached = false;
}
}
// private
function onShow(m){
var last = active.last();
lastShow = new Date();
active.add(m);
if(!attached){
map.enable();
Ext.getDoc().on(&quot;mousedown&quot;, onMouseDown);
attached = true;
}
if(m.parentMenu){
m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle(&quot;z-index&quot;), 10) + 3);
m.parentMenu.activeChild = m;
}else if(last &amp;&amp; !last.isDestroyed &amp;&amp; last.isVisible()){
m.getEl().setZIndex(parseInt(last.getEl().getStyle(&quot;z-index&quot;), 10) + 3);
}
}
// private
function onBeforeHide(m){
if(m.activeChild){
m.activeChild.hide();
}
if(m.autoHideTimer){
clearTimeout(m.autoHideTimer);
delete m.autoHideTimer;
}
}
// private
function onBeforeShow(m){
var pm = m.parentMenu;
if(!pm &amp;&amp; !m.allowOtherMenus){
hideAll();
}else if(pm &amp;&amp; pm.activeChild){
pm.activeChild.hide();
}
}
// private
function onMouseDown(e){
if(lastShow.getElapsed() &gt; 50 &amp;&amp; active.length &gt; 0 &amp;&amp; !e.getTarget(&quot;.x-menu&quot;)){
hideAll();
}
}
return {
<span id='Ext-menu-MenuMgr-method-hideAll'> /**
</span> * Hides all menus that are currently visible
* @return {Boolean} success True if any active menus were hidden.
*/
hideAll : function(){
return hideAll();
},
// private
register : function(menu){
if(!menus){
init();
}
menus[menu.id] = menu;
menu.on({
beforehide: onBeforeHide,
hide: onHide,
beforeshow: onBeforeShow,
show: onShow
});
},
<span id='Ext-menu-MenuMgr-method-get'> /**
</span> * 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 return a new Menu instance.
* @return {Ext.menu.Menu} The specified menu, or null if none are found
*/
get : function(menu){
if(typeof menu == &quot;string&quot;){ // menu id
if(!menus){ // not initialized, no menus to return
return null;
}
return menus[menu];
}else if(menu.events){ // menu instance
return menu;
}else if(typeof menu.length == 'number'){ // array of menu items?
return new Ext.menu.Menu({items:menu});
}else{ // otherwise, must be a config
return Ext.create(menu, 'menu');
}
},
// private
unregister : function(menu){
delete menus[menu.id];
menu.un(&quot;beforehide&quot;, onBeforeHide);
menu.un(&quot;hide&quot;, onHide);
menu.un(&quot;beforeshow&quot;, onBeforeShow);
menu.un(&quot;show&quot;, onShow);
},
// private
registerCheckable : function(menuItem){
var g = menuItem.group;
if(g){
if(!groups[g]){
groups[g] = [];
}
groups[g].push(menuItem);
}
},
// private
unregisterCheckable : function(menuItem){
var g = menuItem.group;
if(g){
groups[g].remove(menuItem);
}
},
// private
onCheckChange: function(item, state){
if(item.group &amp;&amp; state){
var group = groups[item.group],
i = 0,
len = group.length,
current;
for(; i &lt; len; i++){
current = group[i];
if(current != item){
current.setChecked(false);
}
}
}
},
getCheckedItem : function(groupId){
var g = groups[groupId];
if(g){
for(var i = 0, l = g.length; i &lt; l; i++){
if(g[i].checked){
return g[i];
}
}
}
return null;
},
setCheckedItem : function(groupId, itemId){
var g = groups[groupId];
if(g){
for(var i = 0, l = g.length; i &lt; l; i++){
if(g[i].id == itemId){
g[i].setChecked(true);
}
}
}
return null;
}
};
}();
</pre>
</body>
</html>