📄 menu.js
字号:
/*** @method _removeItemFromGroupByValue* @description Removes a menu item from a group by reference. Returns the * menu item that was removed.* @private* @param {Number} p_nGroupIndex Number indicating the group to which the* menu item belongs.* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem * instance to be removed.* @return {YAHOO.widget.MenuItem}*/ _removeItemFromGroupByValue: function (p_nGroupIndex, p_oItem) { var aGroup = this._getItemGroup(p_nGroupIndex), nItems, nItemIndex, returnVal, i; if (aGroup) { nItems = aGroup.length; nItemIndex = -1; if (nItems > 0) { i = nItems-1; do { if (aGroup[i] == p_oItem) { nItemIndex = i; break; } } while (i--); if (nItemIndex > -1) { returnVal = this._removeItemFromGroupByIndex(p_nGroupIndex, nItemIndex); } } } return returnVal;},/*** @method _updateItemProperties* @description Updates the "index," "groupindex," and "className" properties * of the menu items in the specified group. * @private* @param {Number} p_nGroupIndex Number indicating the group of items to update.*/_updateItemProperties: function (p_nGroupIndex) { var aGroup = this._getItemGroup(p_nGroupIndex), nItems = aGroup.length, oItem, oLI, i; if (nItems > 0) { i = nItems - 1; // Update the index and className properties of each member do { oItem = aGroup[i]; if (oItem) { oLI = oItem.element; oItem.index = i; oItem.groupIndex = p_nGroupIndex; oLI.setAttribute(_GROUP_INDEX, p_nGroupIndex); oLI.setAttribute(_INDEX, i); Dom.removeClass(oLI, _FIRST_OF_TYPE); } } while (i--); if (oLI) { Dom.addClass(oLI, _FIRST_OF_TYPE); } }},/*** @method _createItemGroup* @description Creates a new menu item group (array) and its associated * <code><ul></code> element. Returns an aray of menu item groups.* @private* @param {Number} p_nIndex Number indicating the group to create.* @return {Array}*/_createItemGroup: function (p_nIndex) { var oUL, returnVal; if (!this._aItemGroups[p_nIndex]) { this._aItemGroups[p_nIndex] = []; oUL = document.createElement(_UL_LOWERCASE); this._aListElements[p_nIndex] = oUL; returnVal = this._aItemGroups[p_nIndex]; } return returnVal;},/*** @method _getItemGroup* @description Returns the menu item group at the specified index.* @private* @param {Number} p_nIndex Number indicating the index of the menu item group * to be retrieved.* @return {Array}*/_getItemGroup: function (p_nIndex) { var nIndex = Lang.isNumber(p_nIndex) ? p_nIndex : 0, aGroups = this._aItemGroups, returnVal; if (nIndex in aGroups) { returnVal = aGroups[nIndex]; } return returnVal;},/*** @method _configureSubmenu* @description Subscribes the menu item's submenu to its parent menu's events.* @private* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem * instance with the submenu to be configured.*/_configureSubmenu: function (p_oItem) { var oSubmenu = p_oItem.cfg.getProperty(_SUBMENU); if (oSubmenu) { /* Listen for configuration changes to the parent menu so they they can be applied to the submenu. */ this.cfg.configChangedEvent.subscribe(this._onParentMenuConfigChange, oSubmenu, true); this.renderEvent.subscribe(this._onParentMenuRender, oSubmenu, true); }},/*** @method _subscribeToItemEvents* @description Subscribes a menu to a menu item's event.* @private* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem * instance whose events should be subscribed to.*/_subscribeToItemEvents: function (p_oItem) { p_oItem.destroyEvent.subscribe(this._onMenuItemDestroy, p_oItem, this); p_oItem.cfg.configChangedEvent.subscribe(this._onMenuItemConfigChange, p_oItem, this);},/*** @method _onVisibleChange* @description Change event handler for the the menu's "visible" configuration* property.* @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.*/_onVisibleChange: function (p_sType, p_aArgs) { var bVisible = p_aArgs[0]; if (bVisible) { Dom.addClass(this.element, _VISIBLE); } else { Dom.removeClass(this.element, _VISIBLE); }},/*** @method _cancelHideDelay* @description Cancels the call to "hideMenu."* @private*/_cancelHideDelay: function () { var oTimer = this.getRoot()._hideDelayTimer; if (oTimer) { oTimer.cancel(); }},/*** @method _execHideDelay* @description Hides the menu after the number of milliseconds specified by * the "hidedelay" configuration property.* @private*/_execHideDelay: function () { this._cancelHideDelay(); var oRoot = this.getRoot(); oRoot._hideDelayTimer = Lang.later(oRoot.cfg.getProperty(_HIDE_DELAY), this, function () { if (oRoot.activeItem) { if (oRoot.hasFocus()) { oRoot.activeItem.focus(); } oRoot.clearActiveItem(); } if (oRoot == this && !(this instanceof YAHOO.widget.MenuBar) && this.cfg.getProperty(_POSITION) == _DYNAMIC) { this.hide(); } });},/*** @method _cancelShowDelay* @description Cancels the call to the "showMenu."* @private*/_cancelShowDelay: function () { var oTimer = this.getRoot()._showDelayTimer; if (oTimer) { oTimer.cancel(); }},/*** @method _execSubmenuHideDelay* @description Hides a submenu after the number of milliseconds specified by * the "submenuhidedelay" configuration property have ellapsed.* @private* @param {YAHOO.widget.Menu} p_oSubmenu Object specifying the submenu that * should be hidden.* @param {Number} p_nMouseX The x coordinate of the mouse when it left * the specified submenu's parent menu item.* @param {Number} p_nHideDelay The number of milliseconds that should ellapse* before the submenu is hidden.*/_execSubmenuHideDelay: function (p_oSubmenu, p_nMouseX, p_nHideDelay) { p_oSubmenu._submenuHideDelayTimer = Lang.later(50, this, function () { if (this._nCurrentMouseX > (p_nMouseX + 10)) { p_oSubmenu._submenuHideDelayTimer = Lang.later(p_nHideDelay, p_oSubmenu, function () { this.hide(); }); } else { p_oSubmenu.hide(); } });},// Protected methods/*** @method _disableScrollHeader* @description Disables the header used for scrolling the body of the menu.* @protected*/_disableScrollHeader: function () { if (!this._bHeaderDisabled) { Dom.addClass(this.header, _TOP_SCROLLBAR_DISABLED); this._bHeaderDisabled = true; }},/*** @method _disableScrollFooter* @description Disables the footer used for scrolling the body of the menu.* @protected*/_disableScrollFooter: function () { if (!this._bFooterDisabled) { Dom.addClass(this.footer, _BOTTOM_SCROLLBAR_DISABLED); this._bFooterDisabled = true; }},/*** @method _enableScrollHeader* @description Enables the header used for scrolling the body of the menu.* @protected*/_enableScrollHeader: function () { if (this._bHeaderDisabled) { Dom.removeClass(this.header, _TOP_SCROLLBAR_DISABLED); this._bHeaderDisabled = false; }},/*** @method _enableScrollFooter* @description Enables the footer used for scrolling the body of the menu.* @protected*/_enableScrollFooter: function () { if (this._bFooterDisabled) { Dom.removeClass(this.footer, _BOTTOM_SCROLLBAR_DISABLED); this._bFooterDisabled = false; }},/*** @method _onMouseOver* @description "mouseover" 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.*/_onMouseOver: function (p_sType, p_aArgs) { var oEvent = p_aArgs[0], oItem = p_aArgs[1], oTarget = Event.getTarget(oEvent), oRoot = this.getRoot(), oSubmenuHideDelayTimer = this._submenuHideDelayTimer, oParentMenu, nShowDelay, bShowDelay, oActiveItem, oItemCfg, oSubmenu; var showSubmenu = function () { if (this.parent.cfg.getProperty(_SELECTED)) { this.show(); } }; if (!this._bStopMouseEventHandlers) { if (!this._bHandledMouseOverEvent && (oTarget == this.element || Dom.isAncestor(this.element, oTarget))) { // Menu mouseover logic this._nCurrentMouseX = 0; Event.on(this.element, _MOUSEMOVE, this._onMouseMove, this, true); /* If the mouse is moving from the submenu back to its corresponding menu item, don't hide the submenu or clear the active MenuItem. */ if (!(oItem && Dom.isAncestor(oItem.element, Event.getRelatedTarget(oEvent)))) { this.clearActiveItem(); } if (this.parent && oSubmenuHideDelayTimer) { oSubmenuHideDelayTimer.cancel(); this.parent.cfg.setProperty(_SELECTED, true); oParentMenu = this.parent.parent; oParentMenu._bHandledMouseOutEvent = true; oParentMenu._bHandledMouseOverEvent = false; } this._bHandledMouseOverEvent = true; this._bHandledMouseOutEvent = false; } if (oItem && !oItem.handledMouseOverEvent && !oItem.cfg.getProperty(_DISABLED) && (oTarget == oItem.element || Dom.isAncestor(oItem.element, oTarget))) { // Menu Item mouseover logic nShowDelay = this.cfg.getProperty(_SHOW_DELAY); bShowDelay = (nShowDelay > 0); if (bShowDelay) { this._cancelShowDelay(); } oActiveItem = this.activeItem; if (oActiveItem) { oActiveItem.cfg.setProperty(_SELECTED, false); } oItemCfg = oItem.cfg; // Select and focus the current menu item oItemCfg.setProperty(_SELECTED, true); if (this.hasFocus() || oRoot._hasFocus) { oItem.focus();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -