📄 menu.js
字号:
/** * @class Ext.menu.Menu * @extends Ext.util.Observable * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class * when you want a specialzed menu based off of another component (like {@link Ext.menu.DateMenu} for example). * @constructor * Creates a new Menu * @param {Object} config Configuration options */Ext.menu.Menu = function(config){ if(config instanceof Array){ config = {items:config}; } Ext.apply(this, config); this.id = this.id || Ext.id(); this.addEvents({ /** * @event beforeshow * Fires before this menu is displayed * @param {Ext.menu.Menu} this */ beforeshow : true, /** * @event beforehide * Fires before this menu is hidden * @param {Ext.menu.Menu} this */ beforehide : true, /** * @event show * Fires after this menu is displayed * @param {Ext.menu.Menu} this */ show : true, /** * @event hide * Fires after this menu is hidden * @param {Ext.menu.Menu} this */ hide : true, /** * @event click * Fires when this menu is clicked (or when the enter key is pressed while it is active) * @param {Ext.menu.Menu} this * @param {Ext.menu.Item} menuItem The menu item that was clicked * @param {Ext.EventObject} e */ click : true, /** * @event mouseover * Fires when the mouse is hovering over this menu * @param {Ext.menu.Menu} this * @param {Ext.EventObject} e * @param {Ext.menu.Item} menuItem The menu item that was clicked */ mouseover : true, /** * @event mouseout * Fires when the mouse exits this menu * @param {Ext.menu.Menu} this * @param {Ext.EventObject} e * @param {Ext.menu.Item} menuItem The menu item that was clicked */ mouseout : true, /** * @event itemclick * Fires when a menu item contained in this menu is clicked * @param {Ext.menu.BaseItem} baseItem The BaseItem that was clicked * @param {Ext.EventObject} e */ itemclick: true }); Ext.menu.MenuMgr.register(this); var mis = this.items; this.items = new Ext.util.MixedCollection(); if(mis){ this.add.apply(this, mis); }};Ext.extend(Ext.menu.Menu, Ext.util.Observable, { /** * @cfg {Object} defaults * A config object that will be applied to all items added to this container either via the {@link #items} * config or via the {@link #add} method. The defaults config can contain any number of * name/value property pairs to be added to each item, and should be valid for the types of items * being added to the menu. */ /** * @cfg {Mixed} items * An array of items to be added to this menu. See {@link #add} for a list of valid item types. */ /** * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120) */ minWidth : 120, /** * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" * for bottom-right shadow (defaults to "sides") */ shadow : "sides", /** * @cfg {String} subMenuAlign The {@link Ext.Element#alignTo} anchor position value to use for submenus of * this menu (defaults to "tl-tr?") */ subMenuAlign : "tl-tr?", /** * @cfg {String} defaultAlign The default {@link Ext.Element#alignTo) anchor position value for this menu * relative to its element of origin (defaults to "tl-bl?") */ defaultAlign : "tl-bl?", /** * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false) */ allowOtherMenus : false, hidden:true, // private render : function(){ if(this.el){ return; } var el = this.el = new Ext.Layer({ cls: "x-menu", shadow:this.shadow, constrain: false, parentEl: this.parentEl || document.body, zindex:15000 }); this.keyNav = new Ext.menu.MenuNav(this); if(this.plain){ el.addClass("x-menu-plain"); } if(this.cls){ el.addClass(this.cls); } // generic focus element this.focusEl = el.createChild({ tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1" }); var ul = el.createChild({tag: "ul", cls: "x-menu-list"}); ul.on("click", this.onClick, this); ul.on("mouseover", this.onMouseOver, this); ul.on("mouseout", this.onMouseOut, this); this.items.each(function(item){ var li = document.createElement("li"); li.className = "x-menu-list-item"; ul.dom.appendChild(li); item.render(li, this); }, this); this.ul = ul; this.autoWidth(); }, // private autoWidth : function(){ var el = this.el, ul = this.ul; if(!el){ return; } var w = this.width; if(w){ el.setWidth(w); }else if(Ext.isIE){ el.setWidth(this.minWidth); var t = el.dom.offsetWidth; // force recalc el.setWidth(ul.getWidth()+el.getFrameWidth("lr")); } }, // private delayAutoWidth : function(){ if(this.rendered){ if(!this.awTask){ this.awTask = new Ext.util.DelayedTask(this.autoWidth, this); } this.awTask.delay(20); } }, // private findTargetItem : function(e){ var t = e.getTarget(".x-menu-list-item", this.ul, true); if(t && t.menuItemId){ return this.items.get(t.menuItemId); } }, // private onClick : function(e){ var t; if(t = this.findTargetItem(e)){ t.onClick(e); this.fireEvent("click", this, t, e); } }, // private setActiveItem : function(item, autoExpand){ if(item != this.activeItem){ if(this.activeItem){ this.activeItem.deactivate(); } this.activeItem = item; item.activate(autoExpand); }else if(autoExpand){ item.expandMenu(); } }, // private tryActivate : function(start, step){ var items = this.items; for(var i = start, len = items.length; i >= 0 && i < len; i+= step){ var item = items.get(i); if(!item.disabled && item.canActivate){ this.setActiveItem(item, false); return item; } } return false; }, // private onMouseOver : function(e){ var t; if(t = this.findTargetItem(e)){ if(t.canActivate && !t.disabled){ this.setActiveItem(t, true); } } this.fireEvent("mouseover", this, e, t); }, // private onMouseOut : function(e){ var t; if(t = this.findTargetItem(e)){ if(t == this.activeItem && t.shouldDeactivate(e)){ this.activeItem.deactivate(); delete this.activeItem; } } this.fireEvent("mouseout", this, e, t); }, /** * Read-only. Returns true if the menu is currently displayed, else false. * @type Boolean */ isVisible : function(){ return this.el && !this.hidden; }, /** * Displays this menu relative to another element * @param {Mixed} element The element to align to * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to * the element (defaults to this.defaultAlign) * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined) */ show : function(el, pos, parentMenu){ this.parentMenu = parentMenu; if(!this.el){ this.render(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -