plugin.js revision 347511d70b1f81d9b08363612fdabcef8a85e7a6
e371fe50702011b7021c8d79181e88184c23448bAdam Moore/**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* A Button Plugin
e371fe50702011b7021c8d79181e88184c23448bAdam Moore*
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* @module button-plugin
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* @since 3.5.0
e371fe50702011b7021c8d79181e88184c23448bAdam Moore*/
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore/**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* @class ButtonPlugin
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* @param config {Object} Configuration object
e371fe50702011b7021c8d79181e88184c23448bAdam Moore* @constructor
e371fe50702011b7021c8d79181e88184c23448bAdam Moore*/
e371fe50702011b7021c8d79181e88184c23448bAdam Moorefunction ButtonPlugin(config) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore ButtonPlugin.superclass.constructor.apply(this, arguments);
e371fe50702011b7021c8d79181e88184c23448bAdam Moore}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam MooreY.extend(ButtonPlugin, Y.ButtonCore, {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @method _afterNodeGet
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @param name {string}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @private
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore _afterNodeGet: function (name) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore // TODO: point to method (_uiSetLabel, etc) instead of getter/setter
e371fe50702011b7021c8d79181e88184c23448bAdam Moore var ATTRS = this.constructor.ATTRS,
e371fe50702011b7021c8d79181e88184c23448bAdam Moore fn = ATTRS[name] && ATTRS[name].getter && this[ATTRS[name].getter];
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore if (fn) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore return new Y.Do.AlterReturn('get ' + name, fn.call(this));
e371fe50702011b7021c8d79181e88184c23448bAdam Moore }
e371fe50702011b7021c8d79181e88184c23448bAdam Moore },
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @method _afterNodeSet
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @param name {String}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @param val {String}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @private
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore _afterNodeSet: function (name, val) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore var ATTRS = this.constructor.ATTRS,
e371fe50702011b7021c8d79181e88184c23448bAdam Moore fn = ATTRS[name] && ATTRS[name].setter && this[ATTRS[name].setter];
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore if (fn) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore fn.call(this, val);
e371fe50702011b7021c8d79181e88184c23448bAdam Moore }
e371fe50702011b7021c8d79181e88184c23448bAdam Moore },
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @method _initNode
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @param config {Object}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @private
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore _initNode: function(config) {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore var node = config.host;
e371fe50702011b7021c8d79181e88184c23448bAdam Moore this._host = node;
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore Y.Do.after(this._afterNodeGet, node, 'get', this);
e371fe50702011b7021c8d79181e88184c23448bAdam Moore Y.Do.after(this._afterNodeSet, node, 'set', this);
e371fe50702011b7021c8d79181e88184c23448bAdam Moore },
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @method destroy
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @private
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore destroy: function(){
e371fe50702011b7021c8d79181e88184c23448bAdam Moore // Nothing to do, but things are happier with it here
e371fe50702011b7021c8d79181e88184c23448bAdam Moore }
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore}, {
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * Attribute configuration.
e371fe50702011b7021c8d79181e88184c23448bAdam Moore *
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @property ATTRS
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @type {Object}
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @private
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @static
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore ATTRS: Y.merge(Y.ButtonCore.ATTRS),
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * Name of this component.
e371fe50702011b7021c8d79181e88184c23448bAdam Moore *
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @property NAME
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @type String
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @static
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
e371fe50702011b7021c8d79181e88184c23448bAdam Moore NAME: 'buttonPlugin',
e371fe50702011b7021c8d79181e88184c23448bAdam Moore
e371fe50702011b7021c8d79181e88184c23448bAdam Moore /**
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * Namespace of this component.
e371fe50702011b7021c8d79181e88184c23448bAdam Moore *
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @property NS
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @type String
e371fe50702011b7021c8d79181e88184c23448bAdam Moore * @static
e371fe50702011b7021c8d79181e88184c23448bAdam Moore */
NS: 'button'
});
/**
* @method createNode
* @description A factory that plugs a Y.Node instance with Y.Plugin.Button
* @param node {Object}
* @param config {Object}
* @returns {Object} A plugged Y.Node instance
* @public
*/
ButtonPlugin.createNode = function(node, config) {
var template;
if (node && !config) {
if (! (node.nodeType || node.getDOMNode || typeof node == 'string')) {
config = node;
node = config.srcNode;
}
}
config = config || {};
template = config.template || Y.Plugin.Button.prototype.TEMPLATE;
node = node || config.srcNode || Y.DOM.create(template);
return Y.one(node).plug(Y.Plugin.Button, config);
};
Y.namespace('Plugin').Button = ButtonPlugin;