📄 button-beta.js
字号:
else if (p_oElement.nodeName) { if (!oConfig.attributes.id) { if (p_oElement.id) { oConfig.attributes.id = p_oElement.id; } else { oConfig.attributes.id = Dom.generateId(); } } oConfig.attributes.srcelement = p_oElement; initConfig.call(this, oConfig); if (!oConfig.element) { oConfig.element = this.createButtonElement(oConfig.attributes.type); } fnSuperClass.call(this, oConfig.element, oConfig.attributes); } } }; YAHOO.extend(YAHOO.widget.Button, YAHOO.util.Element, { // Protected properties /** * @property _button * @description Object reference to the button's internal * <code><a></code> or <code><button></code> element. * @default null * @protected * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ * level-one-html.html#ID-48250443">HTMLAnchorElement</a>|<a href=" * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html * #ID-34812697">HTMLButtonElement</a> */ _button: null, /** * @property _menu * @description Object reference to the button's menu. * @default null * @protected * @type {<a href="YAHOO.widget.Overlay.html">YAHOO.widget.Overlay</a>| * <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>} */ _menu: null, /** * @property _hiddenFields * @description Object reference to the <code><input></code> * element, or array of HTML form elements used to represent the button * when its parent form is submitted. * @default null * @protected * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ * level-one-html.html#ID-6043025">HTMLInputElement</a>|Array */ _hiddenFields: null, /** * @property _onclickAttributeValue * @description Object reference to the button's current value for the * "onclick" configuration attribute. * @default null * @protected * @type Object */ _onclickAttributeValue: null, /** * @property _activationKeyPressed * @description Boolean indicating if the key(s) that toggle the button's * "active" state have been pressed. * @default false * @protected * @type Boolean */ _activationKeyPressed: false, /** * @property _activationButtonPressed * @description Boolean indicating if the mouse button that toggles * the button's "active" state has been pressed. * @default false * @protected * @type Boolean */ _activationButtonPressed: false, /** * @property _hasKeyEventHandlers * @description Boolean indicating if the button's "blur", "keydown" and * "keyup" event handlers are assigned * @default false * @protected * @type Boolean */ _hasKeyEventHandlers: false, /** * @property _hasMouseEventHandlers * @description Boolean indicating if the button's "mouseout," * "mousedown," and "mouseup" event handlers are assigned * @default false * @protected * @type Boolean */ _hasMouseEventHandlers: false, // Constants /** * @property NODE_NAME * @description The name of the node to be used for the button's * root element. * @default "SPAN" * @final * @type String */ NODE_NAME: "SPAN", /** * @property CHECK_ACTIVATION_KEYS * @description Array of numbers representing keys that (when pressed) * toggle the button's "checked" attribute. * @default [32] * @final * @type Array */ CHECK_ACTIVATION_KEYS: [32], /** * @property ACTIVATION_KEYS * @description Array of numbers representing keys that (when presed) * toggle the button's "active" state. * @default [13, 32] * @final * @type Array */ ACTIVATION_KEYS: [13, 32], /** * @property OPTION_AREA_WIDTH * @description Width (in pixels) of the area of a split button that * when pressed will display a menu. * @default 20 * @final * @type Number */ OPTION_AREA_WIDTH: 20, /** * @property CSS_CLASS_NAME * @description String representing the CSS class(es) to be applied to * the button's root element. * @default "yui-button" * @final * @type String */ CSS_CLASS_NAME: "yui-button", /** * @property RADIO_DEFAULT_TITLE * @description String representing the default title applied to buttons * of type "radio." * @default "Unchecked. Click to check." * @final * @type String */ RADIO_DEFAULT_TITLE: "Unchecked. Click to check.", /** * @property RADIO_CHECKED_TITLE * @description String representing the title applied to buttons of * type "radio" when checked. * @default "Checked. Click to uncheck." * @final * @type String */ RADIO_CHECKED_TITLE: "Checked. Click to uncheck.", /** * @property CHECKBOX_DEFAULT_TITLE * @description String representing the default title applied to * buttons of type "checkbox." * @default "Unchecked. Click to check." * @final * @type String */ CHECKBOX_DEFAULT_TITLE: "Unchecked. Click to check.", /** * @property CHECKBOX_CHECKED_TITLE * @description String representing the title applied to buttons of type * "checkbox" when checked. * @default "Checked. Click to uncheck." * @final * @type String */ CHECKBOX_CHECKED_TITLE: "Checked. Click to uncheck.", /** * @property MENUBUTTON_DEFAULT_TITLE * @description String representing the default title applied to * buttons of type "menu." * @default "Menu collapsed. Click to expand." * @final * @type String */ MENUBUTTON_DEFAULT_TITLE: "Menu collapsed. Click to expand.", /** * @property MENUBUTTON_MENU_VISIBLE_TITLE * @description String representing the title applied to buttons of type * "menu" when the button's menu is visible. * @default "Menu expanded. Click or press Esc to collapse." * @final * @type String */ MENUBUTTON_MENU_VISIBLE_TITLE: "Menu expanded. Click or press Esc to collapse.", /** * @property SPLITBUTTON_DEFAULT_TITLE * @description String representing the default title applied to * buttons of type "split." * @default "Menu collapsed. Click inside option region or press * Ctrl + Shift + M to show the menu." * @final * @type String */ SPLITBUTTON_DEFAULT_TITLE: ("Menu collapsed. Click inside option " + "region or press Ctrl + Shift + M to show the menu."), /** * @property SPLITBUTTON_OPTION_VISIBLE_TITLE * @description String representing the title applied to buttons of type * "split" when the button's menu is visible. * @default "Menu expanded. Press Esc or Ctrl + Shift + M to hide * the menu." * @final * @type String */ SPLITBUTTON_OPTION_VISIBLE_TITLE: "Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu.", /** * @property SUBMIT_TITLE * @description String representing the title applied to buttons of * type "submit." * @default "Click to submit form." * @final * @type String */ SUBMIT_TITLE: "Click to submit form.", // Protected attribute setter methods /** * @method _setType * @description Sets the value of the button's "type" attribute. * @protected * @param {String} p_sType String indicating the value for the button's * "type" attribute. */ _setType: function (p_sType) { if (p_sType == "split") { this.on("option", this._onOption); } }, /** * @method _setLabel * @description Sets the value of the button's "label" attribute. * @protected * @param {String} p_sLabel String indicating the value for the button's * "label" attribute. */ _setLabel: function (p_sLabel) { this._button.innerHTML = p_sLabel; }, /** * @method _setTabIndex * @description Sets the value of the button's "tabindex" attribute. * @protected * @param {Number} p_nTabIndex Number indicating the value for the * button's "tabindex" attribute. */ _setTabIndex: function (p_nTabIndex) { this._button.tabIndex = p_nTabIndex; }, /** * @method _setTitle * @description Sets the value of the button's "title" attribute. * @protected * @param {String} p_nTabIndex Number indicating the value for * the button's "title" attribute. */ _setTitle: function (p_sTitle) { var sTitle = p_sTitle; if (this.get("type") != "link") { if (!sTitle) { switch (this.get("type")) { case "radio": sTitle = this.RADIO_DEFAULT_TITLE; break; case "checkbox": sTitle = this.CHECKBOX_DEFAULT_TITLE; break; case "menu": sTitle = this.MENUBUTTON_DEFAULT_TITLE; break; case "split": sTitle = this.SPLITBUTTON_DEFAULT_TITLE; break; case "submit": sTitle = this.SUBMIT_TITLE; break; } } this._button.title = sTitle; } }, /** * @method _setDisabled * @description Sets the value of the button's "disabled" attribute. * @protected * @param {Boolean} p_bDisabled Boolean indicating the value for * the button's "disabled" attribute. */ _setDisabled: function (p_bDisabled) { if (this.get("type") != "link") { if (p_bDisabled) { if (this._menu) { this._menu.hide(); } if (this.hasFocus()) { this.blur(); } this._button.setAttribute("disabled", "disabled"); this.addStateCSSClasses("disabled"); } else { this._button.removeAttribute("disabled"); this.removeStateCSSClasses("disabled"); } } }, /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -