📄 menu-debug.js
字号:
if (Lang.isString(p_oElement)) { oElement = Dom.get(p_oElement); } else if (p_oElement.tagName) { oElement = p_oElement; } if (oElement && oElement.tagName) { switch(oElement.tagName.toUpperCase()) { case _DIV_UPPERCASE: this.srcElement = oElement; if (!oElement.id) { oElement.setAttribute(_ID, Dom.generateId()); } /* Note: we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level. */ Menu.superclass.init.call(this, oElement); this.beforeInitEvent.fire(Menu); YAHOO.log("Source element: " + this.srcElement.tagName, "info", this.toString()); break; case _SELECT: this.srcElement = oElement; /* The source element is not something that we can use outright, so we need to create a new Overlay Note: we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level. */ Menu.superclass.init.call(this, Dom.generateId()); this.beforeInitEvent.fire(Menu); YAHOO.log("Source element: " + this.srcElement.tagName, "info", this.toString()); break; } } else { /* Note: we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level. */ Menu.superclass.init.call(this, p_oElement); this.beforeInitEvent.fire(Menu); YAHOO.log("No source element found. Created element with id: " + this.id, "info", this.toString()); } if (this.element) { Dom.addClass(this.element, this.CSS_CLASS_NAME); // Subscribe to Custom Events this.initEvent.subscribe(this._onInit); this.beforeRenderEvent.subscribe(this._onBeforeRender); this.renderEvent.subscribe(this._onRender); this.beforeShowEvent.subscribe(this._onBeforeShow); this.hideEvent.subscribe(this._onHide); this.showEvent.subscribe(this._onShow); this.beforeHideEvent.subscribe(this._onBeforeHide); this.mouseOverEvent.subscribe(this._onMouseOver); this.mouseOutEvent.subscribe(this._onMouseOut); this.clickEvent.subscribe(this._onClick); this.keyDownEvent.subscribe(this._onKeyDown); this.keyPressEvent.subscribe(this._onKeyPress); this.blurEvent.subscribe(this._onBlur); if (UA.gecko || UA.webkit) { this.cfg.subscribeToConfigEvent(_Y, this._onYChange); } if (p_oConfig) { this.cfg.applyConfig(p_oConfig, true); } // Register the Menu instance with the MenuManager MenuManager.addMenu(this); this.initEvent.fire(Menu); }},// Private methods/*** @method _initSubTree* @description Iterates the childNodes of the source element to find nodes * used to instantiate menu and menu items.* @private*/_initSubTree: function () { var oSrcElement = this.srcElement, sSrcElementTagName, nGroup, sGroupTitleTagName, oNode, aListElements, nListElements, i; if (oSrcElement) { sSrcElementTagName = (oSrcElement.tagName && oSrcElement.tagName.toUpperCase()); if (sSrcElementTagName == _DIV_UPPERCASE) { // Populate the collection of item groups and item group titles oNode = this.body.firstChild; if (oNode) { nGroup = 0; sGroupTitleTagName = this.GROUP_TITLE_TAG_NAME.toUpperCase(); do { if (oNode && oNode.tagName) { switch (oNode.tagName.toUpperCase()) { case sGroupTitleTagName: this._aGroupTitleElements[nGroup] = oNode; break; case _UL_UPPERCASE: this._aListElements[nGroup] = oNode; this._aItemGroups[nGroup] = []; nGroup++; break; } } } while ((oNode = oNode.nextSibling)); /* Apply the "first-of-type" class to the first UL to mimic the ":first-of-type" CSS3 psuedo class. */ if (this._aListElements[0]) { Dom.addClass(this._aListElements[0], _FIRST_OF_TYPE); } } } oNode = null; YAHOO.log("Searching DOM for items to initialize.", "info", this.toString()); if (sSrcElementTagName) { switch (sSrcElementTagName) { case _DIV_UPPERCASE: aListElements = this._aListElements; nListElements = aListElements.length; if (nListElements > 0) { YAHOO.log("Found " + nListElements + " item groups to initialize.", "info", this.toString()); i = nListElements - 1; do { oNode = aListElements[i].firstChild; if (oNode) { YAHOO.log("Scanning " + aListElements[i].childNodes.length + " child nodes for items to initialize.", "info", this.toString()); do { if (oNode && oNode.tagName && oNode.tagName.toUpperCase() == _LI) { YAHOO.log("Initializing " + oNode.tagName + " node.", "info", this.toString()); this.addItem(new this.ITEM_TYPE(oNode, { parent: this }), i); } } while ((oNode = oNode.nextSibling)); } } while (i--); } break; case _SELECT: YAHOO.log("Scanning " + oSrcElement.childNodes.length + " child nodes for items to initialize.", "info", this.toString()); oNode = oSrcElement.firstChild; do { if (oNode && oNode.tagName) { switch (oNode.tagName.toUpperCase()) { case _OPTGROUP: case _OPTION: YAHOO.log("Initializing " + oNode.tagName + " node.", "info", this.toString()); 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 aItems = this.getItems(), nItems = aItems.length, oItem, returnVal; for(var i=0; i<nItems; i++) { oItem = aItems[i]; if (oItem && !oItem.cfg.getProperty(_DISABLED) && oItem.element.style.display != _NONE) { returnVal = oItem; break; } } return returnVal; },/*** @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, nGroupIndex, aGroup, oGroupItem, bAppend, oNextItemSibling, nItemIndex, returnVal; function getNextItemSibling(p_aArray, p_nStartIndex) { return (p_aArray[p_nStartIndex] || getNextItemSibling(p_aArray, (p_nStartIndex+1))); } if (p_oItem instanceof this.ITEM_TYPE) { oItem = p_oItem; oItem.parent = this; } else if (Lang.isString(p_oItem)) { oItem = new this.ITEM_TYPE(p_oItem, { parent: this }); } else if (Lang.isObject(p_oItem)) { p_oItem.parent = this; oItem = new this.ITEM_TYPE(p_oItem.text, p_oItem); } if (oItem) { if (oItem.cfg.getProperty(_SELECTED)) { this.activeItem = oItem; } nGroupIndex = Lang.isNumber(p_nGroupIndex) ? p_nGroupIndex : 0; aGroup = this._getItemGroup(nGroupIndex); if (!aGroup) { aGroup = this._createItemGroup(nGroupIndex); } if (Lang.isNumber(p_nItemIndex)) { 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 { 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); YAHOO.log("Item inserted." + " Text: " + oGroupItem.cfg.getProperty("text") + ", " + " Index: " + oGroupItem.index + ", " + " Group Index: " + oGroupItem.groupIndex, "info", this.toString()); this.itemAddedEvent.fire(oGroupItem); this.changeContentEvent.fire(); returnVal = oGroupItem; } } else { 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(_GROUP_INDEX, nGroupIndex); oGroupItem.element.setAttribute(_INDEX, nItemIndex); oGroupItem.parent = this; oGroupItem.index = nItemIndex; oGroupItem.groupIndex = nGroupIndex; this._subscribeToItemEvents(oGroupItem);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -