menu.js

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

JS
2,751
字号
                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.focusEvent.subscribe(this._onMenuItemFocus, p_oItem, this);    p_oItem.blurEvent.subscribe(this._onMenuItemBlur, this, true);    p_oItem.cfg.configChangedEvent.subscribe(        this._onMenuItemConfigChange,        p_oItem,        this    );},/*** @method _getOffsetWidth* @description Returns the offset width of the menu's* <code>&#60;div&#62;</code> element.* @private*/_getOffsetWidth: function() {    var oClone = this.element.cloneNode(true);    Dom.setStyle(oClone, "width", "");    document.body.appendChild(oClone);    var sWidth = oClone.offsetWidth;    document.body.removeChild(oClone);    return sWidth;},/*** @method _cancelHideDelay* @description Cancels the call to "hideMenu."* @private*/_cancelHideDelay: function() {    var oRoot = this.getRoot();    if(oRoot._nHideDelayId) {        window.clearTimeout(oRoot._nHideDelayId);    }},/*** @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();    var me = this;    var hideMenu = function() {        if(oRoot.activeItem) {            oRoot.clearActiveItem();        }        if(oRoot == me && me.cfg.getProperty("position") == "dynamic") {            me.hide();        }    };    oRoot._nHideDelayId =        window.setTimeout(hideMenu, oRoot.cfg.getProperty("hidedelay"));},/*** @method _cancelShowDelay* @description Cancels the call to the "showMenu."* @private*/_cancelShowDelay: function() {    var oRoot = this.getRoot();    if(oRoot._nShowDelayId) {        window.clearTimeout(oRoot._nShowDelayId);    }},/*** @method _execShowDelay* @description Shows the menu after the number of milliseconds specified by* the "showdelay" configuration property have ellapsed.* @private* @param {YAHOO.widget.Menu} p_oMenu Object specifying the menu that should* be made visible.*/_execShowDelay: function(p_oMenu) {    this._cancelShowDelay();    var oRoot = this.getRoot();    var showMenu = function() {        p_oMenu.show();    };    oRoot._nShowDelayId =        window.setTimeout(showMenu, oRoot.cfg.getProperty("showdelay"));},// Protected methods/*** @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.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onMouseOver: function(p_sType, p_aArgs, p_oMenu) {    var oEvent = p_aArgs[0];    var oItem = p_aArgs[1];    var oTarget = Event.getTarget(oEvent);    if(        !this._bHandledMouseOverEvent &&        (oTarget == this.element || Dom.isAncestor(this.element, oTarget))    ) {        // MENU  MOUSEOVER LOGIC HERE        this.clearActiveItem();        this._bHandledMouseOverEvent = true;        this._bHandledMouseOutEvent = false;    }    if(        oItem && !oItem.handledMouseOverEvent &&        (oTarget == oItem.element || Dom.isAncestor(oItem.element, oTarget))    ) {        var oItemCfg = oItem.cfg;        // Select and focus the current menu item        oItemCfg.setProperty("selected", true);        oItem.focus();        if(this.cfg.getProperty("autosubmenudisplay")) {            // Show the submenu this menu item            var oSubmenu = oItemCfg.getProperty("submenu");            if(oSubmenu) {                if(this.cfg.getProperty("showdelay") > 0) {                    this._execShowDelay(oSubmenu);                }                else {                    oSubmenu.show();                }            }        }        oItem.handledMouseOverEvent = true;        oItem.handledMouseOutEvent = false;    }},/*** @method _onMouseOut* @description "mouseout" 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.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onMouseOut: function(p_sType, p_aArgs, p_oMenu) {    var oEvent = p_aArgs[0];    var oItem = p_aArgs[1];    var oRelatedTarget = Event.getRelatedTarget(oEvent);    var bMovingToSubmenu = false;    if(oItem) {        var oItemCfg = oItem.cfg;        var oSubmenu = oItemCfg.getProperty("submenu");        if(            oSubmenu &&            (                oRelatedTarget == oSubmenu.element ||                Dom.isAncestor(oSubmenu.element, oRelatedTarget)            )        ) {            bMovingToSubmenu = true;        }        if(            !oItem.handledMouseOutEvent &&            (                (                    oRelatedTarget != oItem.element &&                    !Dom.isAncestor(oItem.element, oRelatedTarget)                ) || bMovingToSubmenu            )        ) {            if(this.cfg.getProperty("showdelay") > 0) {                this._cancelShowDelay();            }            if(!bMovingToSubmenu) {                oItemCfg.setProperty("selected", false);            }            if(this.cfg.getProperty("autosubmenudisplay")) {                if(oSubmenu) {                    if(                        !(                            oRelatedTarget == oSubmenu.element ||                            YAHOO.util.Dom.isAncestor(                                oSubmenu.element,                                oRelatedTarget                            )                        )                    ) {                        oSubmenu.hide();                    }                }            }            oItem.handledMouseOutEvent = true;            oItem.handledMouseOverEvent = false;        }    }    if(        !this._bHandledMouseOutEvent &&        (            (                oRelatedTarget != this.element &&                !Dom.isAncestor(this.element, oRelatedTarget)            )            || bMovingToSubmenu        )    ) {        this._bHandledMouseOutEvent = true;        this._bHandledMouseOverEvent = false;    }},/*** @method _onClick* @description "click" 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.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onClick: function(p_sType, p_aArgs, p_oMenu) {    var oEvent = p_aArgs[0];    var oItem = p_aArgs[1];    var oTarget = Event.getTarget(oEvent);    if(oItem) {        var oItemCfg = oItem.cfg;        var oSubmenu = oItemCfg.getProperty("submenu");        /*            ACCESSIBILITY FEATURE FOR SCREEN READERS:            Expand/collapse the submenu when the user clicks            on the submenu indicator image.        */        if(oTarget == oItem.submenuIndicator && oSubmenu) {            if(oSubmenu.cfg.getProperty("visible")) {                oSubmenu.hide();            }            else {                this.clearActiveItem();                this.activeItem = oItem;                oItem.cfg.setProperty("selected", true);                oSubmenu.show();            }        }        else {            var sURL = oItemCfg.getProperty("url");            var bCurrentPageURL = (sURL.substr((sURL.length-1),1) == "#");            var sTarget = oItemCfg.getProperty("target");            var bHasTarget = (sTarget && sTarget.length > 0);            /*                Prevent the browser from following links                equal to "#"            */            if(                oTarget.tagName.toUpperCase() == "A" &&                bCurrentPageURL && !bHasTarget            ) {                Event.preventDefault(oEvent);            }            if(                oTarget.tagName.toUpperCase() != "A" &&                !bCurrentPageURL && !bHasTarget            ) {                /*                    Follow the URL of the item regardless of                    whether or not the user clicked specifically                    on the anchor element.                */                document.location = sURL;            }            /*                If the item doesn't navigate to a URL and it doesn't have                a submenu, then collapse the menu tree.            */            if(bCurrentPageURL && !oSubmenu) {                var oRoot = this.getRoot();                if(oRoot.cfg.getProperty("position") == "static") {                    oRoot.clearActiveItem();                }                else {                    oRoot.hide();                }            }        }    }},/*** @method _onKeyDown* @description "keydown" 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.* @param {YAHOO.widget.Menu} p_oMenu Object representing the menu that* fired the event.*/_onKeyDown: function(p_sType, p_aArgs, p_oMenu) {    var oEvent = p_aArgs[0];    var oItem = p_aArgs[1];    var oSubmenu;    if(oItem) {        var oItemCfg = oItem.cfg;        var oParentItem = this.parent;        var oRoot;        var oNextItem;        switch(oEvent.keyCode) {            case 38:    // Up arrow            case 40:    // Down arrow                if(                    oItem == this.activeItem &&                    !oItemCfg.getProperty("selected")                ) {                    oItemCfg.setProperty("selected", true);                }                else {                    oNextItem = (oEvent.keyCode == 38) ?                        oItem.getPreviousEnabledSibling() :                        oItem.getNextEnabledSibling();                    if(oNextItem) {                        this.clearActiveItem();                        oNextItem.cfg.setProperty("selected", true);                        oNextItem.focus();                    }                }                Event.preventDefault(oEvent);            break;            case 39:    // Right arrow                oSubmenu = oItemCfg.getProperty("submenu");                if(oSubmenu) {                    if(!oItemCfg.getProperty("selected")) {                        oItemCfg.setProperty("selected", true);                    }                    oSubmenu.show();                    oSubmenu.setInitialSelection();                }                else {                    oRoot = this.getRoot();                    if(oRoot instanceof YAHOO.widget.MenuBar) {                        oNextItem = oRoot.activeItem.getNextEnabledSibling();                        if(oNextItem) {                            oRoot.clearActiveItem();                            oNextItem.cfg.setProperty("selected", true);                            oSubmenu = oNextItem.cfg.getProperty("submenu");                            if(oSubmenu) {                                oSubmenu.show();                            }                            oNextItem.focus();                        }                    }                }                Event.preventDefault(oEvent);            break;            case 37:    // Left arrow                if(oParentItem) {                    var oParentMenu = oParentItem.parent;                    if(oParentMenu instanceof YAHOO.widget.MenuBar) {

⌨️ 快捷键说明

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