⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.js

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JS
📖 第 1 页 / 共 5 页
字号:
        switch(oElement.tagName) {

            case "DIV":

                this.srcElement = oElement;

                /*
                    Note: we don't pass the user config in here yet
                    because we only want it executed once, at the lowest
                    subclass level.
                */

                YAHOO.widget.MenuModule.superclass.init.call(this, oElement);

                this.beforeInitEvent.fire(YAHOO.widget.MenuModule);

                /*
                    Populate the collection of item groups and item
                    group titles
                */

                var oNode = this.body.firstChild;
                var i = 0;

                do {

                    switch(oNode.tagName) {

                        case this.GROUP_TITLE_TAG_NAME:

                            this._aGroupTitleElements[i] = oNode;

                        break;

                        case "UL":

                            this._aListElements[i] = oNode;
                            this._aItemGroups[i] = [];
                            i++;

                        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");

                }



            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
                */

                var sId = 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.
                */

                YAHOO.widget.MenuModule.superclass.init.call(this, sId);

                this.beforeInitEvent.fire(YAHOO.widget.MenuModule);



            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.
        */

        YAHOO.widget.MenuModule.superclass.init.call(this, p_oElement);

        this.beforeInitEvent.fire(YAHOO.widget.MenuModule);



    }

    if(this.element) {

        var oEl = this.element;
        var CustomEvent = YAHOO.util.CustomEvent;

        Dom.addClass(oEl, this.CSS_CLASS_NAME);

        // Assign DOM event handlers

        if(YAHOO.widget.MenuModule._initEventHandlers) {

            var oDoc = document;
            var onDOMEvent = YAHOO.widget.MenuModule._onDOMEvent;

            Event.addListener(oDoc, "mouseover", onDOMEvent);
            Event.addListener(oDoc, "mouseout", onDOMEvent);
            Event.addListener(oDoc, "mousedown", onDOMEvent);
            Event.addListener(oDoc, "mouseup", onDOMEvent);
            Event.addListener(oDoc, "click", onDOMEvent);
            Event.addListener(oDoc, "keydown", onDOMEvent);
            Event.addListener(oDoc, "keyup", onDOMEvent);
            Event.addListener(oDoc, "keypress", onDOMEvent);

            YAHOO.widget.MenuModule._initEventHandlers = false;

        }

        // Create custom events

        this.mouseOverEvent = new CustomEvent("mouseOverEvent", this);
        this.mouseOutEvent = new CustomEvent("mouseOutEvent", this);
        this.mouseDownEvent = new CustomEvent("mouseDownEvent", this);
        this.mouseUpEvent = new CustomEvent("mouseUpEvent", this);
        this.clickEvent = new CustomEvent("clickEvent", this);
        this.keyPressEvent = new CustomEvent("keyPressEvent", this);
        this.keyDownEvent = new CustomEvent("keyDownEvent", this);
        this.keyUpEvent = new CustomEvent("keyUpEvent", this);

        // Subscribe to Custom Events

        this.initEvent.subscribe(this._onInit, this, true);
        this.beforeRenderEvent.subscribe(this._onBeforeRender, this, true);
        this.renderEvent.subscribe(this._onRender, this, true);
        this.showEvent.subscribe(this._onShow, this, true);
        this.beforeHideEvent.subscribe(this._onBeforeHide, this, true);

        if(p_oConfig) {

            this.cfg.applyConfig(p_oConfig, true);

        }

        this.cfg.queueProperty("visible", false);

        if(this.srcElement) {

            this._initSubTree();

        }

        YAHOO.widget.MenuModule._menus[oEl.id] = this;

    }

    this.initEvent.fire(YAHOO.widget.MenuModule);

};

// Private methods

/**
* Iterates the source element's childNodes collection and uses the child
* nodes to instantiate MenuModule and MenuModuleItem instances.
* @private
*/
YAHOO.widget.MenuModule.prototype._initSubTree = function() {

    var oNode;


    switch(this.srcElement.tagName) {

        case "DIV":

            if(this._aListElements.length > 0) {


                var i = this._aListElements.length - 1;

                do {

                    oNode = this._aListElements[i].firstChild;


                    do {

                        switch(oNode.tagName) {

                            case "LI":


                                this.addItem(new this.ITEM_TYPE(oNode), i);

                            break;

                        }

                    }
                    while((oNode = oNode.nextSibling));

                }
                while(i--);

            }

        break;

        case "SELECT":


            oNode = this.srcElement.firstChild;

            do {

                switch(oNode.tagName) {

                    case "OPTGROUP":
                    case "OPTION":


                        this.addItem(new this.ITEM_TYPE(oNode));

                    break;

                }

            }
            while((oNode = oNode.nextSibling));

        break;

    }

};

/**
* Returns the first enabled item in a menu instance.
* @return Returns a MenuModuleItem instance.
* @type YAHOO.widget.MenuModuleItem
* @private
*/
YAHOO.widget.MenuModule.prototype._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;

            }

        }

    }

};

/**
* Determines if the value is one of the supported positions.
* @private
* @param {Object} p_sPosition The object to be evaluated.
* @return Returns true if the position is supported.
* @type Boolean
*/
YAHOO.widget.MenuModule.prototype._checkPosition = function(p_sPosition) {

    if(typeof p_sPosition == "string") {

        var sPosition = p_sPosition.toLowerCase();

        return ("dynamic,static".indexOf(sPosition) != -1);

    }

};

/**
* Adds an item to a group.
* @private
* @param {Number} p_nGroupIndex Number indicating the group to which
* the item belongs.
* @param {YAHOO.widget.MenuModuleItem} p_oItem The item to be added.
* @param {Number} p_nItemIndex Optional. Index at which the item
* should be added.
* @return The item that was added.
* @type YAHOO.widget.MenuModuleItem
*/
YAHOO.widget.MenuModule.prototype._addItemToGroup =

    function(p_nGroupIndex, p_oItem, p_nItemIndex) {

        var Dom = this._oDom;
        var oItem;

        if(p_oItem instanceof this.ITEM_TYPE) {

            oItem = p_oItem;

        }
        else if(typeof p_oItem == "string") {

            oItem = new this.ITEM_TYPE(p_oItem);

        }

        if(oItem) {

            var sYUIId = Dom.generateId();

            oItem.element.setAttribute("yuiid", sYUIId);

            YAHOO.widget.MenuModule._menuItems[sYUIId] = 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
                        * @param {p_aArray} An array
                        * @param {p_nStartIndex} The index to start searching
                        * the array
                        * @ignore
                        * @return Returns an item in an array
                        * @type Object
                        */
                        function getNextItemSibling(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._configureItemSubmenuModule(oGroupItem);

                    this._updateItemProperties(nGroupIndex);


                    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._configureItemSubmenuModule(oGroupItem);

                    if(nItemIndex === 0) {

                        Dom.addClass(oGroupItem.element, "first-of-type");

                    }


                    return oGroupItem;

                }

            }

        }

⌨️ 快捷键说明

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