WidgetButtons Class
Provides header/body/footer button support for Widgets that use the
WidgetStdMod
extension.
This Widget extension makes it easy to declaratively configure a widget's
buttons. It adds a buttons
attribute along with button- accessor and mutator
methods. All button nodes have the Y.Plugin.Button
plugin applied.
This extension also includes HTML_PARSER
support to seed a widget's buttons
from those which already exist in its DOM.
Item Index
Methods
Properties
Attributes
Methods
addButton
-
button
-
[section="footer"]
-
[index]
Adds a button to this widget.
The new button node will have the Y.Plugin.Button
plugin applied, be added
to this widget's buttons
, and rendered in the specified section
at the
specified index
(or end of the section when no index
is provided). If
the section does not exist, it will be created.
This fires the buttonsChange
event and adds the following properties to
the event facade:
-
button
: The button node or config object to add. -
section
: TheWidgetStdMod
section (header/body/footer) where the button will be added. -
index
: The index at which the button will be in the section. -
src
: "add"
Note: The index
argument will be passed to the Array splice()
method, therefore a negative value will insert the button
that many items
from the end. The index
property on the buttonsChange
event facade is
the index at which the button
was added.
Parameters:
-
button
Node | Object | StringThe button to add. This can be a
Y.Node
instance, config Object, or String name for a predefined button on theBUTTONS
prototype property. When a config Object is provided, it will be merged with any defaults provided by anysrcNode
and/or a button with the samename
defined on theBUTTONS
property. The following are the possible configuration properties beyond what Node plugins accept by default:-
[action]
Function | String optionalThe default handler that should be called when the button is clicked. A String name of a Function that exists on the
context
object can also be provided. Note: Specifying a set ofevents
will override this setting. -
[classNames]
String | String[] optionalAdditional CSS classes to add to the button node.
-
[context=this]
Object optionalContext which any
events
oraction
should be called with. Defaults tothis
, the widget. Note:e.target
will access the button node in the event handlers. -
[disabled=false]
Boolean optionalWhether the button should be disabled.
-
[events="click"]
String | Object optionalEvent name, or set of events and handlers to bind to the button node. See:
Y.Node.on()
, this value is passed as the first argument toon()
. -
[isDefault=false]
Boolean optionalWhether the button is the default button.
-
[label]
String optionalThe visible text/value displayed in the button.
-
[name]
String optionalA name which can later be used to reference this button. If a button is defined on the
BUTTONS
property with this same name, its configuration properties will be merged in as defaults. -
[section]
String optionalThe
WidgetStdMod
section (header, body, footer) where the button should be added. -
[srcNode]
Node optionalAn existing Node to use for the button, default values will be seeded from this node, but are overriden by any values specified in the config object. By default a new <button> node will be created.
-
[template]
String optionalA specific template to use when creating a new button node (e.g. "<a />"). Note: Specifying a
srcNode
will overide this.
-
-
[section="footer"]
String optionalThe
WidgetStdMod
section (header/body/footer) where the button should be added. This takes precedence over thebutton.section
configuration property. -
[index]
Number optionalThe index at which the button should be inserted. If not specified, the button will be added to the end of the section. This value is passed to the Array
splice()
method, therefore a negative value will insert thebutton
that many items from the end.
getButton
-
name
-
[section="footer"]
Returns a button node from this widget's buttons
.
Parameters:
Returns:
The button node.
removeButton
-
button
-
[section="footer"]
Removes a button from this widget.
The button will be removed from this widget's buttons
and its DOM. Any
event subscriptions on the button which were created by this widget will be
detached. If the content section becomes empty after removing the button
node, then the section will also be removed.
This fires the buttonsChange
event and adds the following properties to
the event facade:
-
button
: The button node to remove. -
section
: TheWidgetStdMod
section (header/body/footer) where the button should be removed from. -
index
: The index at which the button exists in the section. -
src
: "remove"
Parameters:
-
button
Node | Number | StringThe button to remove. This can be a
Y.Node
instance, index, or String name of a button. -
[section="footer"]
String optionalThe
WidgetStdMod
section (header/body/footer) where the button exists. Only applicable when removing a button by numerical index, or by name but scoped to a particular section.
Properties
BUTTONS
Object
Collection of predefined buttons mapped by name -> config.
These button configurations will serve as defaults for any button added to a
widget's buttons which have the same name
.
See addButton()
for a list of possible configuration values.
Default: {}
BUTTONS_TEMPLATE
String
The HTML template to use when creating the node which wraps all buttons of a section. By default it will have the CSS class: "yui3-widget-buttons".
Default: "<span />"
DEFAULT_BUTTONS_SECTION
String
The default section to render buttons in when no section is specified.
Default: Y.WidgetStdMod.FOOTER
NON_BUTTON_NODE_CFG
Array
static
The list of button configuration properties which are specific to
WidgetButtons
and should not be passed to Y.Plugin.Button.createNode()
.
Attributes
defaultButton
Node
readonly
The current default button as configured through this widget's buttons
.
A button can be configured as the default button in the following ways:
-
As a config Object with an
isDefault
property:{label: 'Okay', isDefault: true}
. -
As a Node with a
data-default
attribute:<button data-default="true">Okay</button>
.
This attribute is read-only; anytime there are changes to this widget's
buttons
, the defaultButton
will be updated if needed.
Note: If two or more buttons are configured to be the default button, the last one wins.
Default: null
Fires event defaultButtonChange
Fires when the value for the configuration attribute defaultButton
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added: