2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('button', function (Y, NAME) {
17 var ButtonCore = Y.ButtonCore,
18 CLASS_NAMES = ButtonCore.CLASS_NAMES,
19 ARIA_STATES = ButtonCore.ARIA_STATES,
20 ARIA_ROLES = ButtonCore.ARIA_ROLES;
28 * @param config {Object} Configuration object
32 Button.superclass.constructor.apply(this, arguments);
35 /* Button extends Widget */
36 Y.extend(Button, Y.Widget, {
38 // Y.Button prototype properties
41 * Bounding box template that will contain the Button's DOM subtree.
43 * @property BOUNDING_TEMPLATE
47 BOUNDING_TEMPLATE : ButtonCore.prototype.TEMPLATE,
50 * Content box template
52 * @property CONTENT_TEMPLATE
56 CONTENT_TEMPLATE : null
60 // Y.Button static properties
63 * The identity of the widget.
72 NAME: ButtonCore.NAME,
75 * Static property used to define the default attribute configuration of
83 ATTRS: ButtonCore.ATTRS,
86 * The text of the button's label
93 * The HTML of the button's label
95 * This attribute accepts HTML and inserts it into the DOM **without**
96 * sanitization. This attribute should only be used with HTML that has
97 * either been escaped (using `Y.Escape.html`), or sanitized according to
98 * the requirements of your application.
100 * If all you need is support for text labels, please use the `label`
103 * @attribute labelHTML
108 * @property HTML_PARSER
114 labelHTML: ButtonCore._getHTMLFromNode,
115 disabled: ButtonCore._getDisabledFromNode
119 * List of class names used in the Button's DOM
121 * @property CLASS_NAMES
125 CLASS_NAMES: CLASS_NAMES
128 Y.mix(Button.prototype, ButtonCore.prototype);
131 * Creates a ToggleButton
133 * @class ToggleButton
135 * @param config {Object} Configuration object
138 function ToggleButton() {
139 Button.superclass.constructor.apply(this, arguments);
142 // TODO: move to ButtonCore subclass to enable toggle plugin, widget, etc.
143 /* ToggleButton extends Button */
144 Y.extend(ToggleButton, Button, {
158 * @property selectedAttrName
162 selectedAttrName: '',
166 * @method initializer
168 initializer: function (config) {
170 type = button.get('type'),
171 selectedAttrName = (type === "checkbox" ? 'checked' : 'pressed'),
172 selectedState = config[selectedAttrName] || false;
174 // Create the checked/pressed attribute
175 button.addAttr(selectedAttrName, {
179 button.selectedAttrName = selectedAttrName;
186 destructor: function () {
187 delete this.selectedAttrName;
192 * @description Hooks up events for the widget
196 cb = button.get('contentBox');
198 ToggleButton.superclass.bindUI.call(button);
200 cb.on(button.trigger, button.toggle, button);
201 button.after(button.selectedAttrName + 'Change', button._afterSelectedChange);
206 * @description Syncs the UI for the widget
210 cb = button.get('contentBox'),
211 type = button.get('type'),
212 ROLES = ToggleButton.ARIA_ROLES,
213 role = (type === 'checkbox' ? ROLES.CHECKBOX : ROLES.TOGGLE),
214 selectedAttrName = button.selectedAttrName;
216 ToggleButton.superclass.syncUI.call(button);
218 cb.set('role', role);
219 button._uiSetSelected(button.get(selectedAttrName));
223 * @method _afterSelectedChange
226 _afterSelectedChange: function(e){
227 this._uiSetSelected(e.newVal);
231 * @method _uiSetSelected
234 _uiSetSelected: function(value) {
236 cb = button.get('contentBox'),
237 STATES = ToggleButton.ARIA_STATES,
238 type = button.get('type'),
239 ariaState = (type === 'checkbox' ? STATES.CHECKED : STATES.PRESSED);
241 cb.toggleClass(Button.CLASS_NAMES.SELECTED, value);
242 cb.set(ariaState, value);
247 * @description Toggles the selected/pressed/checked state of a ToggleButton
252 button._set(button.selectedAttrName, !button.get(button.selectedAttrName));
258 * The identity of the widget.
262 * @default 'buttongroup'
267 NAME: 'toggleButton',
270 * Static property used to define the default attribute configuration of
288 writeOnce: 'initOnly'
293 * @property HTML_PARSER
299 checked: function(node) {
300 return node.hasClass(CLASS_NAMES.SELECTED);
302 pressed: function(node) {
303 return node.hasClass(CLASS_NAMES.SELECTED);
308 * @property ARIA_STATES
313 ARIA_STATES: ARIA_STATES,
316 * @property ARIA_ROLES
321 ARIA_ROLES: ARIA_ROLES,
324 * Array of static constants used to identify the classnames applied to DOM nodes
326 * @property CLASS_NAMES
330 CLASS_NAMES: CLASS_NAMES
336 Y.ToggleButton = ToggleButton;
339 }, '3.13.0', {"requires": ["button-core", "cssbutton", "widget"]});