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

📄 button.js

📁 很棒的在线教学系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
                },                        /**        * @method _setTarget        * @description Sets the value of the button's "target" attribute.        * @protected        * @param {String} p_sTarget String indicating the value for the button's         * "target" attribute.        */        _setTarget: function (p_sTarget) {                    if (this.get("type") == "link") {                        this._button.setAttribute("target", p_sTarget);                        }                },                        /**        * @method _setChecked        * @description Sets the value of the button's "target" attribute.        * @protected        * @param {Boolean} p_bChecked Boolean indicating the value for          * the button's "checked" attribute.        */        _setChecked: function (p_bChecked) {                    var sType = this.get("type"),                sTitle;                    if (sType == "checkbox" || sType == "radio") {                        if (p_bChecked) {                            this.addStateCSSClasses("checked");                                        sTitle = (sType == "radio") ?                                 this.RADIO_CHECKED_TITLE :                                 this.CHECKBOX_CHECKED_TITLE;                                }                else {                    this.removeStateCSSClasses("checked");                            sTitle = (sType == "radio") ?                                 this.RADIO_DEFAULT_TITLE :                                 this.CHECKBOX_DEFAULT_TITLE;                                }        		if (!this._hasDefaultTitle) {                        	this.set("title", sTitle);                                }                    }                },                        /**        * @method _setMenu        * @description Sets the value of the button's "menu" attribute.        * @protected        * @param {Object} p_oMenu Object indicating the value for the button's         * "menu" attribute.        */        _setMenu: function (p_oMenu) {            var bLazyLoad = this.get("lazyloadmenu"),                oButtonElement = this.get("element"),                sMenuCSSClassName,                        /*                    Boolean indicating if the value of p_oMenu is an instance                     of YAHOO.widget.Menu or YAHOO.widget.Overlay.                */                        bInstance = false,                        oMenu,                oMenuElement,                oSrcElement,                aItems,                nItems,                oItem,                i;        			function onAppendTo() {				oMenu.render(oButtonElement.parentNode);								this.removeListener("appendTo", onAppendTo);						}									function setMenuContainer() {				oMenu.cfg.queueProperty("container", oButtonElement.parentNode);								this.removeListener("appendTo", setMenuContainer);						}			function initMenu() {						var oContainer;						if (oMenu) {					Dom.addClass(oMenu.element, this.get("menuclassname"));					Dom.addClass(oMenu.element, "yui-" + this.get("type") + "-button-menu");					oMenu.showEvent.subscribe(this._onMenuShow, null, this);					oMenu.hideEvent.subscribe(this._onMenuHide, null, this);					oMenu.renderEvent.subscribe(this._onMenuRender, null, this);					if (Menu && oMenu instanceof Menu) {						if (bLazyLoad) {							oContainer = this.get("container");							if (oContainer) {								oMenu.cfg.queueProperty("container", oContainer);							}							else {								this.on("appendTo", setMenuContainer);							}						}						oMenu.cfg.queueProperty("clicktohide", false);						oMenu.keyDownEvent.subscribe(this._onMenuKeyDown, this, true);						oMenu.subscribe("click", this._onMenuClick, this, true);						oMenu.itemAddedEvent.subscribe(this._onMenuItemAdded, this, true);								oSrcElement = oMenu.srcElement;								if (oSrcElement && oSrcElement.nodeName.toUpperCase() == "SELECT") {											oSrcElement.style.display = "none";							oSrcElement.parentNode.removeChild(oSrcElement);								}							}					else if (Overlay && oMenu instanceof Overlay) {								if (!m_oOverlayManager) {									m_oOverlayManager = new YAHOO.widget.OverlayManager();												}												m_oOverlayManager.register(oMenu);											}									this._menu = oMenu;							if (!bInstance && !bLazyLoad) {								if (Dom.inDocument(oButtonElement)) {								oMenu.render(oButtonElement.parentNode);												}						else {									this.on("appendTo", onAppendTo);												}										}						}					}                    if (Overlay) {        				if (Menu) {									sMenuCSSClassName = Menu.prototype.CSS_CLASS_NAME;								}							if (p_oMenu && Menu && (p_oMenu instanceof Menu)) {								oMenu = p_oMenu;					aItems = oMenu.getItems();					nItems = aItems.length;					bInstance = true;											if (nItems > 0) {									i = nItems - 1;									do {										oItem = aItems[i];										if (oItem) {											oItem.cfg.subscribeToConfigEvent("selected", 									this._onMenuItemSelected, oItem, this);										}									}						while (i--);								}								initMenu.call(this);							}				else if (Overlay && p_oMenu && (p_oMenu instanceof Overlay)) {								oMenu = p_oMenu;					bInstance = true;								oMenu.cfg.queueProperty("visible", false);								initMenu.call(this);							}				else if (Menu && Lang.isArray(p_oMenu)) {					oMenu = new Menu(Dom.generateId(), { lazyload: bLazyLoad, itemdata: p_oMenu });											this._menu = oMenu;								this.on("appendTo", initMenu);							}				else if (Lang.isString(p_oMenu)) {								oMenuElement = Dom.get(p_oMenu);								if (oMenuElement) {									if (Menu && Dom.hasClass(oMenuElement, sMenuCSSClassName) || 							oMenuElement.nodeName.toUpperCase() == "SELECT") {											oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });											initMenu.call(this);										}						else if (Overlay) {										oMenu = new Overlay(p_oMenu, { visible: false });											initMenu.call(this);										}								}							}				else if (p_oMenu && p_oMenu.nodeName) {								if (Menu && Dom.hasClass(p_oMenu, sMenuCSSClassName) || 							p_oMenu.nodeName.toUpperCase() == "SELECT") {									oMenu = new Menu(p_oMenu, { lazyload: bLazyLoad });											initMenu.call(this);								}					else if (Overlay) {									if (!p_oMenu.id) {													Dom.generateId(p_oMenu);												}									oMenu = new Overlay(p_oMenu, { visible: false });									initMenu.call(this);										}								}                        }                },                        /**        * @method _setOnClick        * @description Sets the value of the button's "onclick" attribute.        * @protected        * @param {Object} p_oObject Object indicating the value for the button's         * "onclick" attribute.        */        _setOnClick: function (p_oObject) {                    /*                Remove any existing listeners if a "click" event handler                 has already been specified.            */                    if (this._onclickAttributeValue &&                 (this._onclickAttributeValue != p_oObject)) {                        this.removeListener("click", this._onclickAttributeValue.fn);                        this._onclickAttributeValue = null;                    }                            if (!this._onclickAttributeValue &&                 Lang.isObject(p_oObject) &&                 Lang.isFunction(p_oObject.fn)) {                        this.on("click", p_oObject.fn, p_oObject.obj, p_oObject.scope);                        this._onclickAttributeValue = p_oObject;                    }                },                        /**        * @method _setSelectedMenuItem        * @description Sets the value of the button's         * "selectedMenuItem" attribute.        * @protected        * @param {Number} p_nIndex Number representing the index of the item         * in the button's menu that is currently selected.        */        _setSelectedMenuItem: function (p_nIndex) {            var oMenu = this._menu,                oMenuItem;            if (Menu && oMenu && oMenu instanceof Menu) {                oMenuItem = oMenu.getItem(p_nIndex);                                if (oMenuItem && !oMenuItem.cfg.getProperty("selected")) {                                    oMenuItem.cfg.setProperty("selected", true);                                }                        }        },                        // Protected methods                        /**        * @method _isActivationKey        * @description Determines if the specified keycode is one that toggles          * the button's "active" state.        * @protected        * @param {Number} p_nKeyCode Number representing the keycode to         * be evaluated.        * @return {Boolean}        */        _isActivationKey: function (p_nKeyCode) {                    var sType = this.get("type"),                aKeyCodes = (sType == "checkbox" || sType == "radio") ?                     this.CHECK_ACTIVATION_KEYS : this.ACTIVATION_KEYS,                        nKeyCodes = aKeyCodes.length,                bReturnVal = false,                i;                    if (nKeyCodes > 0) {                        i = nKeyCodes - 1;                        do {                            if (p_nKeyCode == aKeyCodes[i]) {                                bReturnVal = true;                        break;                            }                        }                while (i--);                        }                        return bReturnVal;                },                        /**        * @method _isSplitButtonOptionKey        * @description Determines if the specified keycode is one that toggles          * the display of the split button's menu.        * @protected        * @param {Event} p_oEvent Object representing the DOM event object          * passed back by the event utility (YAHOO.util.Event).        * @return {Boolean}        */        _isSplitButtonOptionKey: function (p_oEvent) {			var bShowMenu = (Event.getCharCode(p_oEvent) == 40);			var onKeyPress = function (p_oEvent) {				Event.preventDefault(p_oEvent);				this.removeListener("keypress", onKeyPress);						};			// Prevent the browser from scrolling the window			if (bShowMenu) {				if (UA.opera) {						this.on("keypress", onKeyPress);					}				Event.preventDefault(p_oEvent);			}            return bShowMenu;                },                        /**        * @method _addListenersToForm        * @description Adds event handlers to the button's form.        * @protected        */        _addListenersToForm: function () {                    var oForm = this.getForm(),                onFormKeyPress = YAHOO.widget.Button.onFormKeyPress,                bHasKeyPressListener,                oSrcElement,                aListeners,                nListeners,                i;                            if (oForm) {                        Event.on(oForm, "reset", this._onFormReset, null, this);                Event.on(oForm, "submit", this._onFormSubmit, null, this);

⌨️ 快捷键说明

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