menu-debug.js
来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 2,820 行 · 第 1/5 页
JS
2,820 行
* @description "keydown" event handler for the menu.* @protected* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onKeyDown: function(p_sType, p_aArgs, p_oMenu) { var oEvent = p_aArgs[0]; var oItem = p_aArgs[1]; var oSubmenu; if(oItem) { var oItemCfg = oItem.cfg; var oParentItem = this.parent; var oRoot; var oNextItem; switch(oEvent.keyCode) { case 38: // Up arrow case 40: // Down arrow if( oItem == this.activeItem && !oItemCfg.getProperty("selected") ) { oItemCfg.setProperty("selected", true); } else { oNextItem = (oEvent.keyCode == 38) ? oItem.getPreviousEnabledSibling() : oItem.getNextEnabledSibling(); if(oNextItem) { this.clearActiveItem(); oNextItem.cfg.setProperty("selected", true); oNextItem.focus(); } } Event.preventDefault(oEvent); break; case 39: // Right arrow oSubmenu = oItemCfg.getProperty("submenu"); if(oSubmenu) { if(!oItemCfg.getProperty("selected")) { oItemCfg.setProperty("selected", true); } oSubmenu.show(); oSubmenu.setInitialSelection(); } else { oRoot = this.getRoot(); if(oRoot instanceof YAHOO.widget.MenuBar) { oNextItem = oRoot.activeItem.getNextEnabledSibling(); if(oNextItem) { oRoot.clearActiveItem(); oNextItem.cfg.setProperty("selected", true); oSubmenu = oNextItem.cfg.getProperty("submenu"); if(oSubmenu) { oSubmenu.show(); } oNextItem.focus(); } } } Event.preventDefault(oEvent); break; case 37: // Left arrow if(oParentItem) { var oParentMenu = oParentItem.parent; if(oParentMenu instanceof YAHOO.widget.MenuBar) { oNextItem = oParentMenu.activeItem.getPreviousEnabledSibling(); if(oNextItem) { oParentMenu.clearActiveItem(); oNextItem.cfg.setProperty("selected", true); oSubmenu = oNextItem.cfg.getProperty("submenu"); if(oSubmenu) { oSubmenu.show(); } oNextItem.focus(); } } else { this.hide(); oParentItem.focus(); } } Event.preventDefault(oEvent); break; } } if(oEvent.keyCode == 27) { // Esc key if(this.cfg.getProperty("position") == "dynamic") { this.hide(); if(this.parent) { this.parent.focus(); } } else if(this.activeItem) { oSubmenu = this.activeItem.cfg.getProperty("submenu"); if(oSubmenu && oSubmenu.cfg.getProperty("visible")) { oSubmenu.hide(); this.activeItem.focus(); } else { this.activeItem.cfg.setProperty("selected", false); this.activeItem.blur(); } } Event.preventDefault(oEvent); }},// Private methods/*** @method _onInit* @description "init" event handler for the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onInit: function(p_sType, p_aArgs, p_oMenu) { if( ( (this.parent && !this.lazyLoad) || (!this.parent && this.cfg.getProperty("position") == "static") || ( !this.parent && !this.lazyLoad && this.cfg.getProperty("position") == "dynamic" ) ) && this.getItemGroups().length === 0 ) { if(this.srcElement) { this._initSubTree(); } if(this.itemData) { this.addItems(this.itemData); } } else if(this.lazyLoad) { this.cfg.fireQueue(); }},/*** @method _onBeforeRender* @description "beforerender" event handler for the menu. Appends all of the* <code><ul></code>, <code><li></code> and their accompanying* title elements to the body element of the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onBeforeRender: function(p_sType, p_aArgs, p_oMenu) { var oConfig = this.cfg; var oEl = this.element; var nListElements = this._aListElements.length; if(nListElements > 0) { var i = 0; var bFirstList = true; var oUL; var oGroupTitle; do { oUL = this._aListElements[i]; if(oUL) { if(bFirstList) { Dom.addClass(oUL, "first-of-type"); bFirstList = false; } if(!Dom.isAncestor(oEl, oUL)) { this.appendToBody(oUL); } oGroupTitle = this._aGroupTitleElements[i]; if(oGroupTitle) { if(!Dom.isAncestor(oEl, oGroupTitle)) { oUL.parentNode.insertBefore(oGroupTitle, oUL); } Dom.addClass(oUL, "hastitle"); } } i++; } while(i < nListElements); }},/*** @method _onRender* @description "render" event handler for the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onRender: function(p_sType, p_aArgs, p_oMenu) { if(this.cfg.getProperty("position") == "dynamic") { var sWidth = this.element.parentNode.tagName.toUpperCase() == "BODY" ? this.element.offsetWidth : this._getOffsetWidth(); this.cfg.setProperty("width", (sWidth + "px")); }},/*** @method _onBeforeShow* @description "beforeshow" event handler for the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onBeforeShow: function(p_sType, p_aArgs, p_oMenu) { if(this.lazyLoad && this.getItemGroups().length === 0) { if(this.srcElement) { this._initSubTree(); } if(this.itemData) { if( this.parent && this.parent.parent && this.parent.parent.srcElement && this.parent.parent.srcElement.tagName.toUpperCase() == "SELECT" ) { var nOptions = this.itemData.length; for(var n=0; n<nOptions; n++) { if(this.itemData[n].tagName) { this.addItem((new this.ITEM_TYPE(this.itemData[n]))); } } } else { this.addItems(this.itemData); } } if(this.srcElement) { this.render(); } else { if(this.parent) { this.render(this.parent.element); } else { this.render(this.cfg.getProperty("container")); } } }},/*** @method _onShow* @description "show" event handler for the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that fired* the event.*/_onShow: function(p_sType, p_aArgs, p_oMenu) { this.setInitialFocus(); var oParent = this.parent; if(oParent) { var oParentMenu = oParent.parent; var aParentAlignment = oParentMenu.cfg.getProperty("submenualignment"); var aAlignment = this.cfg.getProperty("submenualignment"); if( (aParentAlignment[0] != aAlignment[0]) && (aParentAlignment[1] != aAlignment[1]) ) { this.cfg.setProperty( "submenualignment", [ aParentAlignment[0], aParentAlignment[1] ] ); } if( !oParentMenu.cfg.getProperty("autosubmenudisplay") && oParentMenu.cfg.getProperty("position") == "static" ) { oParentMenu.cfg.setProperty("autosubmenudisplay", true); /** * "click" event handler for the document * @private * @param {Event} p_oEvent Object reference for the DOM event object * passed back by the event utility (YAHOO.util.Event). */ var disableAutoSubmenuDisplay = function(p_oEvent) { if( p_oEvent.type == "mousedown" || (p_oEvent.type == "keydown" && p_oEvent.keyCode == 27) ) { /* Set the "autosubmenudisplay" to "false" if the user clicks outside the menu bar. */ var oTarget = Event.getTarget(p_oEvent); if( oTarget != oParentMenu.element || !YAHOO.util.Dom.isAncestor(oParentMenu.element, oTarget) ) { oParentMenu.cfg.setProperty( "autosubmenudisplay", false ); Event.removeListener( document, "mousedown", disableAutoSubmenuDisplay ); Event.removeListener( document, "keydown", disableAutoSubmenuDisplay ); } } }; Event.addListener(document, "mousedown", disableAutoSubmenuDisplay); Event.addListener(document, "keydown", disableAutoSubmenuDisplay); } }},/*** @method _onBeforeHide* @description "beforehide" event handler for the menu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that fired* the event.*/_onBeforeHide: function(p_sType, p_aArgs, p_oMenu) { this.clearActiveItem(true);},/*** @method _onParentMenuConfigChange* @description "configchange" event handler for a submenu.* @private* @param {String} p_sType String representing the name of the event that* was fired.* @param {Array} p_aArgs Array of arguments sent when the event was fired.* @param {YAHOO.widget.Menu} p_oSubmenu Object representing the submenu that* subscribed to the event.*/_onParentMenuConfigChange: function(p_sType, p_aArgs, p_oSubmenu) { var sPropertyName = p_aArgs[0][0]; var oPropertyValue = p_aArgs[0][1]; switch(sProper
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?