1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('button-group', function (Y, NAME) {
5
* A Widget to create groups of buttons
11
var CONTENT_BOX = "contentBox",
12
CLICK_EVENT = "click",
13
CLASS_NAMES = Y.ButtonCore.CLASS_NAMES;
16
* Creates a ButtonGroup
20
* @param config {Object} Configuration object
23
function ButtonGroup() {
24
ButtonGroup.superclass.constructor.apply(this, arguments);
27
/* ButtonGroup extends Widget */
28
Y.ButtonGroup = Y.extend(ButtonGroup, Y.Widget, {
32
* @description Creates a visual representation of the widget based on existing parameters.
35
renderUI: function() {
36
this.getButtons().plug(Y.Plugin.Button);
41
* @description Hooks up events for the widget
46
cb = group.get(CONTENT_BOX);
48
cb.delegate(CLICK_EVENT, group._handleClick, Y.ButtonGroup.BUTTON_SELECTOR, group);
53
* @description Returns all buttons inside this this button group
56
getButtons: function() {
57
var cb = this.get(CONTENT_BOX);
59
return cb.all(Y.ButtonGroup.BUTTON_SELECTOR);
63
* @method getSelectedButtons
64
* @description Returns all Y.Buttons instances that are selected
67
getSelectedButtons: function() {
70
buttons = group.getButtons(),
71
selectedClass = ButtonGroup.CLASS_NAMES.SELECTED;
73
buttons.each(function(node){
74
if (node.hasClass(selectedClass)){
83
* @method getSelectedValues
84
* @description Returns the values of all Y.Button instances that are selected
87
getSelectedValues: function() {
88
var selected = this.getSelectedButtons(),
92
Y.Array.each(selected, function(node){
93
value = node.getContent();
101
* @method _handleClick
102
* @description A delegated click handler for when any button is clicked in the content box
103
* @param e {Object} An event object
106
_handleClick: function(e){
108
clickedNode = e.target.ancestor('.' + ButtonGroup.CLASS_NAMES.BUTTON, true),
109
type = group.get('type'),
110
selectedClass = ButtonGroup.CLASS_NAMES.SELECTED,
111
isSelected = clickedNode.hasClass(selectedClass),
114
// TODO: Anything for 'push' groups?
115
if (type === 'checkbox') {
116
clickedNode.toggleClass(selectedClass, !isSelected);
118
* @event selectionChange
119
* @description fires when any button in the group changes its checked status
120
* @param {Event} the event object. It contains an "originEvent" property
121
* linking to the original DOM event that triggered the selection change
123
group.fire('selectionChange', {originEvent: e});
125
else if (type === 'radio' && !isSelected) {
126
buttons = group.getButtons(); // Todo: getSelectedButtons()? Need it to return an arraylist then.
127
buttons.removeClass(selectedClass);
128
clickedNode.addClass(selectedClass);
129
group.fire('selectionChange', {originEvent: e});
134
// Y.ButtonGroup static properties
137
* The identity of the widget.
141
* @default 'buttongroup'
149
* Static property used to define the default attribute configuration of
164
writeOnce: 'initOnly',
170
* List of class names to use for ButtonGroups
172
* @property CLASS_NAMES
176
CLASS_NAMES: CLASS_NAMES,
179
* Selector used to find buttons inside a ButtonGroup
180
* @property BUTTON_SELECTOR
183
BUTTON_SELECTOR: "button, input[type=button], input[type=reset], input[type=submit], input[type=radio], input[type=checkbox]"
187
}, '3.9.1', {"requires": ["button-plugin", "cssbutton", "widget"]});