menu-debug.js
来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 2,820 行 · 第 1/5 页
JS
2,820 行
Dom.addClass(this._aListElements[0], "first-of-type"); } } oNode = null; this.logger.log("Searching DOM for items to initialize."); if(this.srcElement.tagName) { switch(this.srcElement.tagName.toUpperCase()) { case "DIV": if(this._aListElements.length > 0) { this.logger.log("Found " + this._aListElements.length + " item groups to initialize."); var i = this._aListElements.length - 1; do { oNode = this._aListElements[i].firstChild; this.logger.log("Scanning " + this._aListElements[i].childNodes.length + " child nodes for items to initialize."); do { if(oNode && oNode.tagName) { switch(oNode.tagName.toUpperCase()) { case "LI": this.logger.log("Initializing " + oNode.tagName + " node."); this.addItem( new this.ITEM_TYPE( oNode, { parent: this } ), i ); break; } } } while((oNode = oNode.nextSibling)); } while(i--); } break; case "SELECT": this.logger.log("Scanning " + this.srcElement.childNodes.length + " child nodes for items to initialize."); oNode = this.srcElement.firstChild; do { if(oNode && oNode.tagName) { switch(oNode.tagName.toUpperCase()) { case "OPTGROUP": case "OPTION": this.logger.log("Initializing " + oNode.tagName + " node."); this.addItem( new this.ITEM_TYPE( oNode, { parent: this } ) ); break; } } } while((oNode = oNode.nextSibling)); break; } }},/*** @method _getFirstEnabledItem* @description Returns the first enabled item in the menu.* @return {YAHOO.widget.MenuItem}* @private*/_getFirstEnabledItem: function() { var nGroups = this._aItemGroups.length; var oItem; var aItemGroup; for(var i=0; i<nGroups; i++) { aItemGroup = this._aItemGroups[i]; if(aItemGroup) { var nItems = aItemGroup.length; for(var n=0; n<nItems; n++) { oItem = aItemGroup[n]; if( !oItem.cfg.getProperty("disabled") && oItem.element.style.display != "none" ) { return oItem; } oItem = null; } } }},/*** @method _checkPosition* @description Checks to make sure that the value of the "position" property* is one of the supported strings. Returns true if the position is supported.* @private* @param {Object} p_sPosition String specifying the position of the menu.* @return {Boolean}*/_checkPosition: function(p_sPosition) { if(typeof p_sPosition == "string") { var sPosition = p_sPosition.toLowerCase(); return ("dynamic,static".indexOf(sPosition) != -1); }},/*** @method _addItemToGroup* @description Adds a menu item to a group.* @private* @param {Number} p_nGroupIndex Number indicating the group to which the* item belongs.* @param {YAHOO.widget.MenuItem} p_oItem Object reference for the MenuItem* instance to be added to the menu.* @param {String} p_oItem String specifying the text of the item to be added* to the menu.* @param {Object} p_oItem Object literal containing a set of menu item* configuration properties.* @param {Number} p_nItemIndex Optional. Number indicating the index at* which the menu item should be added.* @return {YAHOO.widget.MenuItem}*/_addItemToGroup: function(p_nGroupIndex, p_oItem, p_nItemIndex) { var oItem; if(p_oItem instanceof this.ITEM_TYPE) { oItem = p_oItem; oItem.parent = this; } else if(typeof p_oItem == "string") { oItem = new this.ITEM_TYPE(p_oItem, { parent: this }); } else if(typeof p_oItem == "object" && p_oItem.text) { var sText = p_oItem.text; delete p_oItem["text"]; p_oItem.parent = this; oItem = new this.ITEM_TYPE(sText, p_oItem); } if(oItem) { var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0; var aGroup = this._getItemGroup(nGroupIndex); var oGroupItem; if(!aGroup) { aGroup = this._createItemGroup(nGroupIndex); } if(typeof p_nItemIndex == "number") { var bAppend = (p_nItemIndex >= aGroup.length); if(aGroup[p_nItemIndex]) { aGroup.splice(p_nItemIndex, 0, oItem); } else { aGroup[p_nItemIndex] = oItem; } oGroupItem = aGroup[p_nItemIndex]; if(oGroupItem) { if( bAppend && ( !oGroupItem.element.parentNode || oGroupItem.element.parentNode.nodeType == 11 ) ) { this._aListElements[nGroupIndex].appendChild( oGroupItem.element ); } else { /** * Returns the next sibling of an item in an array. * @private * @param {p_aArray} Array to search. * @param {p_nStartIndex} Number indicating the index to * start searching the array. * @return {Object} */ var getNextItemSibling = function(p_aArray, p_nStartIndex) { return ( p_aArray[p_nStartIndex] || getNextItemSibling( p_aArray, (p_nStartIndex+1) ) ); }; var oNextItemSibling = getNextItemSibling(aGroup, (p_nItemIndex+1)); if( oNextItemSibling && ( !oGroupItem.element.parentNode || oGroupItem.element.parentNode.nodeType == 11 ) ) { this._aListElements[nGroupIndex].insertBefore( oGroupItem.element, oNextItemSibling.element ); } } oGroupItem.parent = this; this._subscribeToItemEvents(oGroupItem); this._configureSubmenu(oGroupItem); this._updateItemProperties(nGroupIndex); this.logger.log("Item inserted." + " Text: " + oGroupItem.cfg.getProperty("text") + ", " + " Index: " + oGroupItem.index + ", " + " Group Index: " + oGroupItem.groupIndex); this.itemAddedEvent.fire(oGroupItem); return oGroupItem; } } else { var nItemIndex = aGroup.length; aGroup[nItemIndex] = oItem; oGroupItem = aGroup[nItemIndex]; if(oGroupItem) { if( !Dom.isAncestor( this._aListElements[nGroupIndex], oGroupItem.element ) ) { this._aListElements[nGroupIndex].appendChild( oGroupItem.element ); } oGroupItem.element.setAttribute("groupindex", nGroupIndex); oGroupItem.element.setAttribute("index", nItemIndex); oGroupItem.parent = this; oGroupItem.index = nItemIndex; oGroupItem.groupIndex = nGroupIndex; this._subscribeToItemEvents(oGroupItem); this._configureSubmenu(oGroupItem); if(nItemIndex === 0) { Dom.addClass(oGroupItem.element, "first-of-type"); } this.logger.log("Item added." + " Text: " + oGroupItem.cfg.getProperty("text") + ", " + " Index: " + oGroupItem.index + ", " + " Group Index: " + oGroupItem.groupIndex); this.itemAddedEvent.fire(oGroupItem); return oGroupItem; } } }},/*** @method _removeItemFromGroupByIndex* @description Removes a menu item from a group by index. Returns the menu* item that was removed.* @private* @param {Number} p_nGroupIndex Number indicating the group to which the menu* item belongs.* @param {Number} p_nItemIndex Number indicating the index of the menu item* to be removed.* @return {YAHOO.widget.MenuItem}*/_removeItemFromGroupByIndex: function(p_nGroupIndex, p_nItemIndex) { var nGroupIndex = typeof p_nGroupIndex == "number" ? p_nGroupIndex : 0; var aGroup = this._getItemGroup(nGroupIndex); if(aGroup) { var aArray = aGroup.splice(p_nItemIndex, 1); var oItem = aArray[0]; if(oItem) { // Update the index and className properties of each member this._updateItemProperties(nGroupIndex); if(aGroup.length === 0) { // Remove the UL var oUL = this._aListElements[nGroupIndex]; if(this.body && oUL) { this.body.removeChild(oUL); } // Remove the group from the array of items this._aItemGroups.splice(nGroupIndex, 1); // Remove the UL from the array of ULs this._aListElements.splice(nGroupIndex, 1); /* Assign the "first-of-type" class to the new first UL in the collection */ oUL = this._aListElements[0]; if(oUL) { Dom.addClass(oUL, "first-of-type"); } } this.itemRemovedEvent.fire(oItem); // Return a reference to the item that was removed return oItem; } }},/*** @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); if(aGroup) { var nItems = aGroup.length; var nItemIndex = -1; if(nItems > 0) { var i = nItems-1; do { if(aGroup[i] == p_oItem) { nItemIndex = i; break; } } while(i--); if(nItemIndex > -1) { return this._removeItemFromGroupByIndex( p_nGroupIndex, nItemIndex ); } } }},/*** @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); var nItems = aGroup.length; if(nItems > 0) { var i = nItems - 1; var oItem; var oLI; // 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("groupindex", p_nGroupIndex); oLI.setAttribute("index", i);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?