base.js revision 800a6a9307a3bbe026f640d20ef73c3d627efc37
/**
* Provides an interface for working with button-like DOM nodes
*
* @module button
* @main button
* @since 3.5.0
*/
/**
* Creates a button
*
* @class Button
* @extends Base
* @param config {Object} Configuration object
* @constructor
*/
}
// -- Private Methods ----------------------------------------------------------
/**
* returns a properly formed yui class name
*
* @method
* @param str {String} string to be appended at the end of class name
* @return
* @private
*/
function makeClassName(str) {
if (str) {
}
else {
}
}
/* Button extends the Base class */
/**
* @method initializer
* @description Internal init() handler.
* @param config {Object} Config object.
* @private
*/
initializer: function(config){
this.bindUI();
},
/**
* @method renderUI
* @private
*/
var button = this;
// Set some default node attributes
// Apply any config attributes that may have been passed in.
// These should always be run
// These are optional
}
}
},
/**
* @method bindUI
* @description Assigns any events listeners to Button instances
* @private
*/
bindUI: function() {
var button = this;
// Listen on some events to handle ARIA & class management
// TODO: hack to make 'click' a Y.Button event until support is built for DOM events.
// You should not use this. Use button.getNode().on() instead.
this.fire('click');
}, button);
// Listen for attribute changes to handle UI updates
});
});
});
});
},
/**
* @method getNode
* @description Returns the Button instance's Y.Node instance
* @return {Object} A node instance
*/
getNode: function() {
return this.get('srcNode');
},
/**
* @method select
* @description Sets a Button's 'selected' attribute to true
*/
select: function() {
this.set('selected', true);
},
/**
* @method unselect
* @description Sets a Button's 'selected' attribute to false
*/
unselect: function() {
this.set('selected', false);
},
/**
* @method enable
* @description Sets a Button's 'disabled' attribute to false
*/
enable: function() {
this.set('disabled', false);
},
/**
* @method disable
* @description Sets a Button's 'disabled' attribute to true
*/
disable: function() {
this.set('disabled', true);
},
/**
* @method on
* @description Determines whether to dispatch events to Y.Node (for DOM events) or Y.EventTarget (for everything else)
* @param {String} type The name of the event
* @param {Function} fn The callback to execute in response to the event
* @param {Object} [context] Override this object in callback
* @param {Any} [arg*] 0..n additional arguments to supply to the subscriber
* @return {EventHandle} A subscription handle capable of detaching that subscription
*/
/*
This is close, but doesn't quite work
on: function(type, fn, ctx, arg) {
//if (false){ // Ugh, can't get it to work properly
if (Y.Lang.isObject(arguments[0])){
// Loop through each event, recursively calling this.on() with the pair
Y.Object.each(arguments[0], function(){
this.on(arguments[1], arguments[0]);
}, this);
// TODO: This should return a batch of events
}
else {
var button = this;
var node = button.getNode();
// Dispatch DOM events to Y.Node, everything else to EventTarget
if (Y.Object.hasKey(Y.Node.DOM_EVENTS, type)) {
return Y.Node.prototype.on.apply(node, arguments);
}
else {
return Y.EventTarget.prototype.on.apply(button, arguments);
}
}
},
*/
/**
* @method _labelSetter
* @description A setter method for the label attribute
* @protected
*/
_renderLabel: function (value) {
},
/**
* @method _disabledSetter
* @description A setter method for the disabled attribute
* @protected
*/
_renderDisabled: function (value) {
},
/**
* @method _selectedSetter
* @description A setter method for the selected attribute
* @protected
*/
_renderSelected: function(value) {
},
/**
* @method _typeSetter
* @description A setter method for the type attribute
* @protected
*/
_renderType: function(value) {
var button = this;
if (value === 'checkbox') {
}
else {
}
}, button);
}
else if (value === 'radio') {
// nothing ?
}
else {
role = 'button';
}
// This probably shouldn't be set, but if it is.
if (button._clickHandler) {
button._clickHandler = false;
}
}
}
}, {
/**
* Array of attributes
*
* @property ATTRS
* @type {Array}
* @private
* @static
*/
ATTRS: {
srcNode: {
writeOnce: 'initOnly',
valueFn: function () {
}
},
label: { },
type: {
value: 'push'
},
disabled: {
value: false
},
selected: {
value: false
}
}
});
// -- Static Properties ----------------------------------------------------------
/**
* Name of this component.
*
* @property NAME
* @type String
* @static
*/
/**
* Array of static constants used to identify the classnames applied to the Button DOM objects
*
* @property CLASS_NAMES
* @type {Array}
* @static
*/
Button.CLASS_NAMES = {
BUTTON : makeClassName(),
}
CHECKED: 'aria-checked',
PRESSED: 'aria-pressed',
}
// -- Protected Methods ----------------------------------------------------------
/**
* @method _onBlur
* @description An event handler for 'blur' events
* @param e {DOMEvent} the event object
* @protected
*/
};
/**
* @method _onFocus
* @description An event handler for 'focus' events
* @param e {DOMEvent} the event object
* @protected
*/
};
// Export Button