button.js revision bb09a8bcec28d3fcfe6649ea17c5042b68ea1627
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* A Button Widget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @module button
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @since 3.5.0
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* Creates a ButtonWidget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @class ButtonWidget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @extends Widget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @param config {Object} Configuration object
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @constructor
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith ButtonWidget.superclass.constructor.apply(this, arguments);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith/* ButtonWidget extends Widget */
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith BOUNDING_TEMPLATE: Y.ButtonCore.prototype.TEMPLATE,
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method initializer
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Internal init() handler.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @param config {Object} Config object.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * bindUI implementation
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Hooks up events for the widget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method bindUI
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith bindUI: function() {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith button.after('labelChange', button._afterLabelChange);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith button.after('disabledChange', button._afterDisabledChange);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method syncUI
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Updates button attributes
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith syncUI: function() {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method _afterLabelChange
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method _afterDisabledChange
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith // Y.Button static properties
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * The identity of the widget.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property NAME
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type String
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @default 'button'
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * Static property used to define the default attribute configuration of
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * the Widget.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property ATTRS
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {Object}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property HTML_PARSER
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {Object}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith return this._getLabel();
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * List of class names used in the ButtonGroup's DOM
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property CLASS_NAMES
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type Object
5d3dc0444c51f18e44c016a89b16a8951529518cLuke SmithY.mix(ButtonWidget.prototype, Y.ButtonCore.prototype);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* Creates a ToggleButton
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @class ToggleButton
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @extends ButtonWidget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @param config {Object} Configuration object
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith* @constructor
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith ButtonWidget.superclass.constructor.apply(this, arguments);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith// TODO: move to ButtonCore subclass to enable toggle plugin, widget, etc.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith/* ToggleButton extends ButtonWidget */
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith selectedAttrName = (type === "checkbox" ? 'checked' : 'pressed'),
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith selectedState = config[selectedAttrName] || false;
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith // Create the checked/pressed attribute
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith destructor: function () {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method bindUI
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Hooks up events for the widget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith bindUI: function() {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith button.after(button.selectedAttrName + 'Change', button._afterSelectedChange);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method bindUI
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Syncs the UI for the widget
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith syncUI: function() {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith role = (type === 'checkbox' ? ROLES.CHECKBOX : ROLES.TOGGLE),
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith button._uiSetSelected(button.get(selectedAttrName));
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method _uiSetSelected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith ariaState = (type === 'checkbox' ? STATES.CHECKED : STATES.PRESSED);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith cb.toggleClass(ButtonWidget.CLASS_NAMES.SELECTED, value);
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @method toggle
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @description Toggles the selected/pressed/checked state of a ToggleButton
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith toggle: function() {
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith button._set(button.selectedAttrName, !button.get(button.selectedAttrName));
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * The identity of the widget.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property NAME
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {String}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @default 'buttongroup'
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * Static property used to define the default attribute configuration of
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * the Widget.
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property ATTRS
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {Object}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property HTML_PARSER
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {Object}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @property ARIA_STATES
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @type {Object}
5d3dc0444c51f18e44c016a89b16a8951529518cLuke Smith * @protected