menu.js

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

JS
2,751
字号
                        oNextItem =                            oParentMenu.activeItem.getPreviousEnabledSibling();                        if(oNextItem) {                            oParentMenu.clearActiveItem();                            oNextItem.cfg.setProperty("selected", true);                            oSubmenu = oNextItem.cfg.getProperty("submenu");                            if(oSubmenu) {                                oSubmenu.show();                            }                            oNextItem.focus();                        }                    }                    else {                        this.hide();                        oParentItem.focus();                    }                }                Event.preventDefault(oEvent);            break;        }    }    if(oEvent.keyCode == 27) { // Esc key        if(this.cfg.getProperty("position") == "dynamic") {            this.hide();            if(this.parent) {                this.parent.focus();            }        }        else if(this.activeItem) {            oSubmenu = this.activeItem.cfg.getProperty("submenu");            if(oSubmenu && oSubmenu.cfg.getProperty("visible")) {                oSubmenu.hide();                this.activeItem.focus();            }            else {                this.activeItem.cfg.setProperty("selected", false);                this.activeItem.blur();            }        }        Event.preventDefault(oEvent);    }},// Private methods/*** @method _onInit* @description "init" event handler for the menu.* @private* @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.*/_onInit: function(p_sType, p_aArgs, p_oMenu) {    if(        (            (this.parent && !this.lazyLoad) ||            (!this.parent && this.cfg.getProperty("position") == "static") ||            (                !this.parent &&                !this.lazyLoad &&                this.cfg.getProperty("position") == "dynamic"            )        ) &&        this.getItemGroups().length === 0    ) {        if(this.srcElement) {            this._initSubTree();        }        if(this.itemData) {            this.addItems(this.itemData);        }    }    else if(this.lazyLoad) {        this.cfg.fireQueue();    }},/*** @method _onBeforeRender* @description "beforerender" event handler for the menu.  Appends all of the* <code>&#60;ul&#62;</code>, <code>&#60;li&#62;</code> and their accompanying* title elements to the body element of the menu.* @private* @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.*/_onBeforeRender: function(p_sType, p_aArgs, p_oMenu) {    var oConfig = this.cfg;    var oEl = this.element;    var nListElements = this._aListElements.length;    if(nListElements > 0) {        var i = 0;        var bFirstList = true;        var oUL;        var oGroupTitle;        do {            oUL = this._aListElements[i];            if(oUL) {                if(bFirstList) {                    Dom.addClass(oUL, "first-of-type");                    bFirstList = false;                }                if(!Dom.isAncestor(oEl, oUL)) {                    this.appendToBody(oUL);                }                oGroupTitle = this._aGroupTitleElements[i];                if(oGroupTitle) {                    if(!Dom.isAncestor(oEl, oGroupTitle)) {                        oUL.parentNode.insertBefore(oGroupTitle, oUL);                    }                    Dom.addClass(oUL, "hastitle");                }            }            i++;        }        while(i < nListElements);    }},/*** @method _onRender* @description "render" event handler for the menu.* @private* @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.*/_onRender: function(p_sType, p_aArgs, p_oMenu) {    if(this.cfg.getProperty("position") == "dynamic") {        var sWidth =            this.element.parentNode.tagName.toUpperCase() == "BODY" ?            this.element.offsetWidth : this._getOffsetWidth();        this.cfg.setProperty("width", (sWidth + "px"));    }},/*** @method _onBeforeShow* @description "beforeshow" event handler for the menu.* @private* @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.*/_onBeforeShow: function(p_sType, p_aArgs, p_oMenu) {    if(this.lazyLoad && this.getItemGroups().length === 0) {        if(this.srcElement) {            this._initSubTree();        }        if(this.itemData) {            if(                this.parent && this.parent.parent &&                this.parent.parent.srcElement &&                this.parent.parent.srcElement.tagName.toUpperCase() == "SELECT"            ) {                var nOptions = this.itemData.length;                for(var n=0; n<nOptions; n++) {                    if(this.itemData[n].tagName) {                        this.addItem((new this.ITEM_TYPE(this.itemData[n])));                    }                }            }            else {                this.addItems(this.itemData);            }        }        if(this.srcElement) {            this.render();        }        else {            if(this.parent) {                this.render(this.parent.element);            }            else {                this.render(this.cfg.getProperty("container"));            }        }    }},/*** @method _onShow* @description "show" event handler for the menu.* @private* @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.*/_onShow: function(p_sType, p_aArgs, p_oMenu) {    this.setInitialFocus();    var oParent = this.parent;    if(oParent) {        var oParentMenu = oParent.parent;        var aParentAlignment = oParentMenu.cfg.getProperty("submenualignment");        var aAlignment = this.cfg.getProperty("submenualignment");        if(            (aParentAlignment[0] != aAlignment[0]) &&            (aParentAlignment[1] != aAlignment[1])        ) {            this.cfg.setProperty(                "submenualignment",                [ aParentAlignment[0], aParentAlignment[1] ]            );        }        if(            !oParentMenu.cfg.getProperty("autosubmenudisplay") &&            oParentMenu.cfg.getProperty("position") == "static"        ) {            oParentMenu.cfg.setProperty("autosubmenudisplay", true);            /**            * "click" event handler for the document            * @private            * @param {Event} p_oEvent Object reference for the DOM event object            * passed back by the event utility (YAHOO.util.Event).            */            var disableAutoSubmenuDisplay = function(p_oEvent) {                if(                    p_oEvent.type == "mousedown" ||                    (p_oEvent.type == "keydown" && p_oEvent.keyCode == 27)                ) {                    /*                        Set the "autosubmenudisplay" to "false" if the user                        clicks outside the menu bar.                    */                    var oTarget = Event.getTarget(p_oEvent);                    if(                        oTarget != oParentMenu.element ||                        !YAHOO.util.Dom.isAncestor(oParentMenu.element, oTarget)                    ) {                        oParentMenu.cfg.setProperty(                            "autosubmenudisplay",                            false                        );                        Event.removeListener(                                document,                                "mousedown",                                disableAutoSubmenuDisplay                            );                        Event.removeListener(                                document,                                "keydown",                                disableAutoSubmenuDisplay                            );                    }                }            };            Event.addListener(document, "mousedown", disableAutoSubmenuDisplay);            Event.addListener(document, "keydown", disableAutoSubmenuDisplay);        }    }},/*** @method _onBeforeHide* @description "beforehide" event handler for the menu.* @private* @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.*/_onBeforeHide: function(p_sType, p_aArgs, p_oMenu) {    this.clearActiveItem(true);},/*** @method _onParentMenuConfigChange* @description "configchange" event handler for a submenu.* @private* @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_oSubmenu Object representing the submenu that* subscribed to the event.*/_onParentMenuConfigChange: function(p_sType, p_aArgs, p_oSubmenu) {    var sPropertyName = p_aArgs[0][0];    var oPropertyValue = p_aArgs[0][1];    switch(sPropertyName) {        case "iframe":        case "constraintoviewport":        case "hidedelay":        case "showdelay":        case "clicktohide":        case "effect":            p_oSubmenu.cfg.setProperty(sPropertyName, oPropertyValue);        break;    }},/*** @method _onParentMenuRender* @description "render" event handler for a submenu.  Renders a* submenu in response to the firing of its parent's "render" event.* @private* @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_oSubmenu Object representing the submenu that* subscribed to the event.*/_onParentMenuRender: function(p_sType, p_aArgs, p_oSubmenu) {    /*        Set the "constraintoviewport" configuration        property to match the parent Menu    */    var oParentMenu = p_oSubmenu.parent.parent;    var oConfig = {            constraintoviewport:                oParentMenu.cfg.getProperty("constraintoviewport"),            xy: [0,0],            clicktohide:                oParentMenu.cfg.getProperty("clicktohide"),            effect:                oParentMenu.cfg.getProperty("effect")        };    var nShowDelay = oParentMenu.cfg.getProperty("showdelay");    if(nShowDelay > 0) {        oConfig.showdelay = nShowDelay;    }    var nHideDelay = oParentMenu.cfg.getProperty("hidedelay");    if(nHideDelay > 0) {        oConfig.hidedelay = nHideDelay;    }    /*        Only sync the "iframe" configuration property if the parent        menu's "position" configuration is the same.    */    if(        this.cfg.getProperty("position") ==        oParentMenu.cfg.getProperty("position")    ) {        oConfig.iframe = oParentMenu.cfg.getProperty("iframe");    }    p_oSubmenu.cfg.applyConfig(oConfig);    if(!this.lazyLoad) {        if(Dom.inDocument(this.element)) {            this.render();        }        else {            this.render(this.parent.element);        }    }},/*** @method _onSubmenuBeforeShow* @description "beforeshow" event handler for a submenu.* @private* @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_oSubmenu Object representing the submenu that* subscribed to the event.*/_onSubmenuBeforeShow: function(p_sType, p_aArgs, p_oSubmenu) {    var oParent = this.parent;    var aAlignment = oParent.parent.cfg.getProperty("submenualignment");    this.cfg.setProperty(        "context",        [oParent.element, aAlignment[0], aAlignment[1]]    );    oParent.submenuIndicator.alt = oParent.EXPANDED_SUBMENU_INDICATOR_ALT_TEXT;

⌨️ 快捷键说明

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