Yahoo! UI Library

Button  2.5.2

Yahoo! UI Library > button > YAHOO.widget.Button

Show Private Show Protected

Class YAHOO.widget.Button - extends YAHOO.util.Element

The Button class creates a rich, graphical button.

Constructor

YAHOO.widget.Button ( p_oElement , p_oAttributes )
Parameters:
p_oElement <String> String specifying the id attribute of the <input>, <button>, <a>, or <span> element to be used to create the button.
p_oElement <HTMLInputElement| HTMLButtonElement|HTMLElement> Object reference for the <input>, <button>, <a>, or <span> element to be used to create the button.
p_oElement <Object> Object literal specifying a set of configuration attributes used to create the button.
p_oAttributes <Object> Optional. Object literal specifying a set of configuration attributes used to create the button.

Properties

ACTIVATION_KEYS - final Array

Array of numbers representing keys that (when presed) toggle the button's "active" state.
Default Value: [13, 32]

CHECK_ACTIVATION_KEYS - final Array

Array of numbers representing keys that (when pressed) toggle the button's "checked" attribute.
Default Value: [32]

CHECKBOX_CHECKED_TITLE - final String

String representing the title applied to buttons of type "checkbox" when checked.
Default Value: "Checked. Click to uncheck."

CHECKBOX_DEFAULT_TITLE - final String

String representing the default title applied to buttons of type "checkbox."
Default Value: "Unchecked. Click to check."

CSS_CLASS_NAME - final String

String representing the CSS class(es) to be applied to the button's root element.
Default Value: "yui-button"

MENUBUTTON_DEFAULT_TITLE - final String

String representing the default title applied to buttons of type "menu."
Default Value: "Menu collapsed. Click to expand."

MENUBUTTON_MENU_VISIBLE_TITLE - final String

String representing the title applied to buttons of type "menu" when the button's menu is visible.
Default Value: "Menu expanded. Click or press Esc to collapse."

NODE_NAME - final String

The name of the node to be used for the button's root element.
Default Value: "SPAN"

OPTION_AREA_WIDTH - final Number

Width (in pixels) of the area of a split button that when pressed will display a menu.
Default Value: 20

RADIO_CHECKED_TITLE - final String

String representing the title applied to buttons of type "radio" when checked.
Default Value: "Checked. Click another button to uncheck"

RADIO_DEFAULT_TITLE - final String

String representing the default title applied to buttons of type "radio."
Default Value: "Unchecked. Click to check."

SPLITBUTTON_DEFAULT_TITLE - final String

String representing the default title applied to buttons of type "split."
Default Value: "Menu collapsed. Click inside option region or press Ctrl + Shift + M to show the menu."

SPLITBUTTON_OPTION_VISIBLE_TITLE - final String

String representing the title applied to buttons of type "split" when the button's menu is visible.
Default Value: "Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu."

SUBMIT_TITLE - final String

String representing the title applied to buttons of type "submit."
Default Value: "Click to submit form."

Properties inherited from YAHOO.util.Element:

Properties inherited from YAHOO.util.AttributeProvider:

Methods

addStateCSSClasses

void addStateCSSClasses ( )
Appends state-specific CSS classes to the button's root DOM element.
Returns: void

blur

void blur ( )
Causes the button to lose focus and fires the button's "blur" event.
Returns: void

createButtonElement

HTMLElement createButtonElement ( p_sType )
Creates the button's HTML elements.
Parameters:
p_sType <String> String indicating the type of element to create.
Returns: HTMLElement

createHiddenFields

HTMLInputElement|Array createHiddenFields ( )
Creates the button's hidden form field and appends it to its parent form.
Returns: HTMLInputElement|Array

destroy

void destroy ( )
Removes the button's element from its parent element and removes all event handlers.
Returns: void

focus

void focus ( )
Causes the button to receive the focus and fires the button's "focus" event.
Returns: void

getForm

HTMLFormElement getForm ( )
Returns a reference to the button's parent form.
Returns: HTMLFormElement

getHiddenFields

HTMLInputElement|Array getHiddenFields ( )
Returns an <input> element or array of form elements used to represent the button when its parent form is submitted.
Returns: HTMLInputElement|Array

getMenu

YAHOO.widget.Overlay|YAHOO.widget.Menu getMenu ( )
Returns a reference to the button's menu.

hasFocus

Boolean hasFocus ( )
Returns a boolean indicating whether or not the button has focus.
Returns: Boolean

init

void init ( p_oElement , p_oAttributes )
The Button class's initialization method.
Parameters:
p_oElement <String> String specifying the id attribute of the <input>, <button>, <a>, or <span> element to be used to create the button.
p_oElement <HTMLInputElement|HTMLButtonElement| HTMLElement> Object reference for the <input>, <button>, <a>, or <span> element to be used to create the button.
p_oElement <Object> Object literal specifying a set of configuration attributes used to create the button.
p_oAttributes <Object> Optional. Object literal specifying a set of configuration attributes used to create the button.
Returns: void

initAttributes

void initAttributes ( p_oAttributes )
Initializes all of the configuration attributes used to create the button.
Parameters:
p_oAttributes <Object> Object literal specifying a set of configuration attributes used to create the button.
Returns: void

isActive

Boolean isActive ( )
Returns a boolean indicating whether or not the button is active.
Returns: Boolean

removeHiddenFields

void removeHiddenFields ( )
Removes the button's hidden form field(s) from its parent form.
Returns: void

removeStateCSSClasses

void removeStateCSSClasses ( )
Removes state-specific CSS classes to the button's root DOM element.
Returns: void

toString

String toString ( )
Returns a string representing the button.
Returns: String

YAHOO.widget.Button.addHiddenFieldsToForm

void YAHOO.widget.Button.addHiddenFieldsToForm ( p_oForm )
Searches the specified form and adds hidden fields for instances of YAHOO.widget.Button that are of type "radio," "checkbox," "menu," and "split."
Parameters:
p_oForm <HTMLFormElement> Object reference for the form to search.
Returns: void

YAHOO.widget.Button.getButton

YAHOO.widget.Button YAHOO.widget.Button.getButton ( p_sId )
Returns a button with the specified id.
Parameters:
p_sId <String> String specifying the id of the root node of the HTML element representing the button to be retrieved.
Returns: YAHOO.widget.Button

YAHOO.widget.Button.onFormKeyPress

void YAHOO.widget.Button.onFormKeyPress ( p_oEvent )
"keypress" event handler for the button's form.
Parameters:
p_oEvent <Event> Object representing the DOM event object passed back by the event utility (YAHOO.util.Event).
Returns: void

Events

beforeCheckedChange

beforeCheckedChange ( eventInfo )
Fires before the value for the configuration attribute 'checked' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeContainerChange

beforeContainerChange ( eventInfo )
Fires before the value for the configuration attribute 'container' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeDisabledChange

beforeDisabledChange ( eventInfo )
Fires before the value for the configuration attribute 'disabled' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeFocusmenuChange

beforeFocusmenuChange ( eventInfo )
Fires before the value for the configuration attribute 'focusmenu' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeHrefChange

beforeHrefChange ( eventInfo )
Fires before the value for the configuration attribute 'href' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeLabelChange

beforeLabelChange ( eventInfo )
Fires before the value for the configuration attribute 'label' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeLazyloadmenuChange

beforeLazyloadmenuChange ( eventInfo )
Fires before the value for the configuration attribute 'lazyloadmenu' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeMenuChange

beforeMenuChange ( eventInfo )
Fires before the value for the configuration attribute 'menu' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeMenuclassnameChange

beforeMenuclassnameChange ( eventInfo )
Fires before the value for the configuration attribute 'menuclassname' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeNameChange

beforeNameChange ( eventInfo )
Fires before the value for the configuration attribute 'name' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeOnclickChange

beforeOnclickChange ( eventInfo )
Fires before the value for the configuration attribute 'onclick' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeSelectedMenuItemChange

beforeSelectedMenuItemChange ( eventInfo )
Fires before the value for the configuration attribute 'selectedMenuItem' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeSrcelementChange

beforeSrcelementChange ( eventInfo )
Fires before the value for the configuration attribute 'srcelement' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeTabindexChange

beforeTabindexChange ( eventInfo )
Fires before the value for the configuration attribute 'tabindex' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeTargetChange

beforeTargetChange ( eventInfo )
Fires before the value for the configuration attribute 'target' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeTitleChange

beforeTitleChange ( eventInfo )
Fires before the value for the configuration attribute 'title' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeTypeChange

beforeTypeChange ( eventInfo )
Fires before the value for the configuration attribute 'type' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

beforeValueChange

beforeValueChange ( eventInfo )
Fires before the value for the configuration attribute 'value' changes. Return false to cancel the attribute change.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the current attribute value and the new value.

blur

blur ( )
Fires when the menu item loses the input focus. Passes back a single object representing the original DOM event object passed back by the event utility (YAHOO.util.Event) when the event was fired. See Element.addListener for more information on listening for this event.

checkedChange

checkedChange ( eventInfo )
Fires when the value for the configuration attribute 'checked' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

containerChange

containerChange ( eventInfo )
Fires when the value for the configuration attribute 'container' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

disabledChange

disabledChange ( eventInfo )
Fires when the value for the configuration attribute 'disabled' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

focus

focus ( )
Fires when the menu item receives focus. Passes back a single object representing the original DOM event object passed back by the event utility (YAHOO.util.Event) when the event was fired. See Element.addListener for more information on listening for this event.

focusmenuChange

focusmenuChange ( eventInfo )
Fires when the value for the configuration attribute 'focusmenu' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

hrefChange

hrefChange ( eventInfo )
Fires when the value for the configuration attribute 'href' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

labelChange

labelChange ( eventInfo )
Fires when the value for the configuration attribute 'label' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

lazyloadmenuChange

lazyloadmenuChange ( eventInfo )
Fires when the value for the configuration attribute 'lazyloadmenu' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

menuChange

menuChange ( eventInfo )
Fires when the value for the configuration attribute 'menu' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

menuclassnameChange

menuclassnameChange ( eventInfo )
Fires when the value for the configuration attribute 'menuclassname' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

nameChange

nameChange ( eventInfo )
Fires when the value for the configuration attribute 'name' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

onclickChange

onclickChange ( eventInfo )
Fires when the value for the configuration attribute 'onclick' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

option

option ( )
Fires when the user invokes the button's option. Passes back a single object representing the original DOM event (either "mousedown" or "keydown") that caused the "option" event to fire. See Element.addListener for more information on listening for this event.

selectedMenuItemChange

selectedMenuItemChange ( eventInfo )
Fires when the value for the configuration attribute 'selectedMenuItem' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

srcelementChange

srcelementChange ( eventInfo )
Fires when the value for the configuration attribute 'srcelement' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

tabindexChange

tabindexChange ( eventInfo )
Fires when the value for the configuration attribute 'tabindex' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

targetChange

targetChange ( eventInfo )
Fires when the value for the configuration attribute 'target' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

titleChange

titleChange ( eventInfo )
Fires when the value for the configuration attribute 'title' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

typeChange

typeChange ( eventInfo )
Fires when the value for the configuration attribute 'type' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

valueChange

valueChange ( eventInfo )
Fires when the value for the configuration attribute 'value' changes.
Parameters:
eventInfo <{oldValue: any, newValue: any}> An object containing the previous attribute value and the new value.

Configuration Attributes

checked - Boolean

Boolean indicating if the button is checked. Applies only to buttons of type "radio" and "checkbox."
Default Value: false

container - HTMLElement|String

HTML element reference or string specifying the id attribute of the HTML element that the button's markup should be rendered into.
Default Value: null

disabled - Boolean

Boolean indicating if the button should be disabled. (Disabled buttons are dimmed and will not respond to user input or fire events. Does not apply to button's of type "link.")
Default Value: false

focusmenu - Boolean

Boolean indicating whether or not the button's menu should be focused when it is made visible.
Default Value: true

href - String

String specifying the href for the button. Applies only to buttons of type "link."

label - String

String specifying the button's text label or innerHTML.
Default Value: null

lazyloadmenu - Boolean

Boolean indicating the value to set for the "lazyload" configuration property of the button's menu. Setting "lazyloadmenu" to true will defer rendering of the button's menu until the first time it is made visible. If "lazyloadmenu" is set to false, the button's menu will be rendered immediately if the button is in the document, or in response to the button's "appendTo" event if the button is not yet in the document. In either case, the menu is rendered into the button's parent HTML element. This attribute does not apply if a YAHOO.widget.Menu or YAHOO.widget.Overlay instance is passed as the value of the button's "menu" configuration attribute. YAHOO.widget.Menu or YAHOO.widget.Overlay instances should be rendered before being set as the value for the "menu" configuration attribute.
Default Value: true

menu - YAHOO.widget.Menu|YAHOO.widget.Overlay|HTMLElement|String|Array

Object specifying the menu for the button. The value can be one of the following:
  • Object specifying a YAHOO.widget.Menu instance.
  • Object specifying a YAHOO.widget.Overlay instance.
  • String specifying the id attribute of the <div> element used to create the menu. By default the menu will be created as an instance of YAHOO.widget.Overlay. If the default CSS class name for YAHOO.widget.Menu is applied to the <div> element, it will be created as an instance of YAHOO.widget.Menu .
  • String specifying the id attribute of the <select> element used to create the menu.
  • Object specifying the <div> element used to create the menu.
  • Object specifying the <select> element used to create the menu.
  • Array of object literals, each representing a set of YAHOO.widget.MenuItem configuration attributes.
  • Array of strings representing the text labels for each menu item in the menu.
Default Value: null

menuclassname - String

String representing the CSS class name to be applied to the root element of the button's menu.
Default Value: "yui-button-menu"

name - String

String specifying the name for the button.
Default Value: null

onclick - Object

Object literal representing the code to be executed when the button is clicked. Format:
{
fn: Function, // The handler to call when the event fires.
obj: Object, // An object to pass back to the handler.
scope: Object // The object to use for the scope of the handler.
}
Default Value: null

selectedMenuItem - Number

Object representing the item in the button's menu that is currently selected.
Default Value: null

srcelement - HTMLElement|String

Object reference to the HTML element (either <input> or <span>) used to create the button.
Default Value: null

tabindex - Number

Number specifying the tabindex for the button.
Default Value: null

target - String

String specifying the target for the button. Applies only to buttons of type "link."

title - String

String specifying the title for the button.
Default Value: null

type - String

String specifying the button's type. Possible values are: "push," "link," "submit," "reset," "checkbox," "radio," "menu," and "split."
Default Value: "push"

value - Object

Object specifying the value for the button.
Default Value: null

Configuration attributes inherited from YAHOO.util.Element:


Copyright © 2007 Yahoo! Inc. All rights reserved.