menu.js

来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 2,751 行 · 第 1/5 页

JS
2,751
字号
                            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.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.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);                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>&#60;ul&#62;</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) {    if(!this._aItemGroups[p_nIndex]) {        this._aItemGroups[p_nIndex] = [];        var oUL = document.createElement("ul");        this._aListElements[p_nIndex] = oUL;        return this._aItemGroups[p_nIndex];    }},/*** @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 = ((typeof p_nIndex == "number") ? p_nIndex : 0);    return this._aItemGroups[nIndex];},/*** @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            );        oSubmenu.beforeShowEvent.subscribe(                this._onSubmenuBeforeShow,                oSubmenu,                true            );        oSubmenu.showEvent.subscribe(                this._onSubmenuShow,                oSubmenu,                true            );        oSubmenu.hideEvent.subscribe(                this._onSubmenuHide,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?