📄 button-beta.js
字号:
Event.on(oElement, "blur", this._onBlur, null, this); Event.on(oElement, "keydown", this._onKeyDown, null, this); Event.on(oElement, "keyup", this._onKeyUp, null, this); this._hasKeyEventHandlers = true; } this.fireEvent("focus", p_oEvent); }, /** * @method _onBlur * @description "blur" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onBlur: function (p_oEvent) { this.removeStateCSSClasses("focus"); if (this.get("type") != "menu") { this.removeStateCSSClasses("active"); } if (this._activationKeyPressed) { Event.on(document, "keyup", this._onDocumentKeyUp, null, this); } m_oFocusedButton = null; this.fireEvent("blur", p_oEvent); }, /** * @method _onDocumentKeyUp * @description "keyup" event handler for the document. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onDocumentKeyUp: function (p_oEvent) { if (this._isActivationKey(Event.getCharCode(p_oEvent))) { this._activationKeyPressed = false; Event.removeListener(document, "keyup", this._onDocumentKeyUp); } }, /** * @method _onKeyDown * @description "keydown" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onKeyDown: function (p_oEvent) { var oMenu = this._menu; if (this.get("type") == "split" && this._isSplitButtonOptionKey(p_oEvent)) { this.fireEvent("option", p_oEvent); } else if (this._isActivationKey(Event.getCharCode(p_oEvent))) { if (this.get("type") == "menu") { this._showMenu(p_oEvent); } else { this._activationKeyPressed = true; this.addStateCSSClasses("active"); } } if (oMenu && oMenu.cfg.getProperty("visible") && Event.getCharCode(p_oEvent) == 27) { oMenu.hide(); this.focus(); } }, /** * @method _onKeyUp * @description "keyup" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onKeyUp: function (p_oEvent) { var sType; if (this._isActivationKey(Event.getCharCode(p_oEvent))) { sType = this.get("type"); if (sType == "checkbox" || sType == "radio") { this.set("checked", !(this.get("checked"))); } this._activationKeyPressed = false; if (this.get("type") != "menu") { this.removeStateCSSClasses("active"); } } }, /** * @method _onClick * @description "click" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onClick: function (p_oEvent) { var sType = this.get("type"), sTitle, oForm, oSrcElement, oElement, nX; switch (sType) { case "radio": case "checkbox": if (this.get("checked")) { sTitle = (sType == "radio") ? this.RADIO_CHECKED_TITLE : this.CHECKBOX_CHECKED_TITLE; } else { sTitle = (sType == "radio") ? this.RADIO_DEFAULT_TITLE : this.CHECKBOX_DEFAULT_TITLE; } this.set("title", sTitle); break; case "submit": this.submitForm(); break; case "reset": oForm = this.getForm(); if (oForm) { oForm.reset(); } break; case "menu": sTitle = this._menu.cfg.getProperty("visible") ? this.MENUBUTTON_MENU_VISIBLE_TITLE : this.MENUBUTTON_DEFAULT_TITLE; this.set("title", sTitle); break; case "split": oElement = this.get("element"); nX = Event.getPageX(p_oEvent) - Dom.getX(oElement); if ((oElement.offsetWidth - this.OPTION_AREA_WIDTH) < nX) { return false; } else { this._hideMenu(); oSrcElement = this.get("srcelement"); if (oSrcElement && oSrcElement.type == "submit") { this.submitForm(); } } sTitle = this._menu.cfg.getProperty("visible") ? this.SPLITBUTTON_OPTION_VISIBLE_TITLE : this.SPLITBUTTON_DEFAULT_TITLE; this.set("title", sTitle); break; } }, /** * @method _onAppendTo * @description "appendTo" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onAppendTo: function (p_oEvent) { /* It is necessary to call "getForm" using "setTimeout" to make sure that the button's "form" property returns a node reference. Sometimes, if you try to get the reference immediately after appending the field, it is null. */ var me = this; window.setTimeout(function () { me._addListenersToForm(); }, 0); }, /** * @method _onFormReset * @description "reset" event handler for the button's form. * @protected * @param {Event} p_oEvent Object representing the DOM event * object passed back by the event utility (YAHOO.util.Event). */ _onFormReset: function (p_oEvent) { var sType = this.get("type"), oMenu = this._menu; if (sType == "checkbox" || sType == "radio") { this.resetValue("checked"); } if (oMenu && (oMenu instanceof Menu)) { this.resetValue("selectedMenuItem"); } }, /** * @method _onDocumentMouseDown * @description "mousedown" event handler for the document. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onDocumentMouseDown: function (p_oEvent) { var oTarget = Event.getTarget(p_oEvent), oButtonElement = this.get("element"), oMenuElement = this._menu.element; if (oTarget != oButtonElement && !Dom.isAncestor(oButtonElement, oTarget) && oTarget != oMenuElement && !Dom.isAncestor(oMenuElement, oTarget)) { this._hideMenu(); Event.removeListener(document, "mousedown", this._onDocumentMouseDown); } }, /** * @method _onOption * @description "option" event handler for the button. * @protected * @param {Event} p_oEvent Object representing the DOM event object * passed back by the event utility (YAHOO.util.Event). */ _onOption: function (p_oEvent) { if (this.hasClass("yui-split-button-activeoption")) { this._hideMenu(); this._bOptionPressed = false; } else { this._showMenu(p_oEvent); this._bOptionPressed = true; } }, /** * @method _onOverlayBeforeShow * @description "beforeshow" event handler for the * <a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a> instance * serving as the button's menu. * @private * @param {String} p_sType String representing the name of the event * that was fired. */ _onOverlayBeforeShow: function (p_sType) { var oMenu = this._menu; oMenu.render(this.get("element").parentNode); oMenu.beforeShowEvent.unsubscribe(this._onOverlayBeforeShow); }, /** * @method _onMenuShow * @description "show" event handler for the button's menu. * @private * @param {String} p_sType String representing the name of the event * that was fired. */ _onMenuShow: function (p_sType) { Event.on(document, "mousedown", this._onDocumentMouseDown, null, this); var sTitle, sState; if (this.get("type") == "split") { sTitle = this.SPLITBUTTON_OPTION_VISIBLE_TITLE; sState = "activeoption"; } else { sTitle = this.MENUBUTTON_MENU_VISIBLE_TITLE; sState = "active"; } this.addStateCSSClasses(sState); this.set("title", sTitle); }, /** * @method _onMenuHide * @description "hide" event handler for the button's menu. * @private * @param {String} p_sType String representing the name of the event * that was fired. */ _onMenuHide: function (p_sType) { var oMenu = this._menu, sTitle, sState; if (oMenu && (oMenu instanceof Menu) && this._originalMaxHeight != -1) { this._menu.cfg.setProperty("maxheight", this._originalMaxHeight); } if (this.get("type") == "split") { sTitle = this.SPLITBUTTON_DEFAULT_TITLE; sState = "activeoption"; } else { sTitle = this.MENUBUTTON_DEFAULT_TITLE; sState = "active"; } this.removeStateCSSClasses(sState); this.set("title", sTitle); if (this.get("t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -