MDL-32843 import YUI 3.5.1
[moodle.git] / lib / yui / 3.5.1 / build / button-plugin / button-plugin.js
blob0225e9b3519d2b68ba33dac7726106d77be257e4
1 /*
2 YUI 3.5.1 (build 22)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('button-plugin', function(Y) {
9 /**
10 * A Button Plugin
12 * @module button-plugin
13 * @since 3.5.0
16 /**
17 * @class ButtonPlugin
18 * @param config {Object} Configuration object
19 * @constructor
21 function ButtonPlugin(config) {
22     ButtonPlugin.superclass.constructor.apply(this, arguments);
25 Y.extend(ButtonPlugin, Y.ButtonCore, {
26     
27     /**
28     * @method _afterNodeGet
29     * @param name {string}
30     * @private
31     */
32     _afterNodeGet: function (name) {
33         // TODO: point to method (_uiSetLabel, etc) instead of getter/setter
34         var ATTRS = this.constructor.ATTRS,
35             fn = ATTRS[name] && ATTRS[name].getter && this[ATTRS[name].getter];
36             
37         if (fn) {
38             return new Y.Do.AlterReturn('get ' + name, fn.call(this));
39         }
40     },
42     /**
43     * @method _afterNodeSet
44     * @param name {String}
45     * @param val {String}
46     * @private
47     */
48     _afterNodeSet: function (name, val) {
49         var ATTRS = this.constructor.ATTRS,
50             fn = ATTRS[name] && ATTRS[name].setter && this[ATTRS[name].setter];
51             
52         if (fn) {
53             fn.call(this, val);
54         }
55     },
57     /**
58     * @method _initNode
59     * @param config {Object}
60     * @private
61     */
62     _initNode: function(config) {
63         var node = config.host;
64         this._host = node;
65         
66         Y.Do.after(this._afterNodeGet, node, 'get', this);
67         Y.Do.after(this._afterNodeSet, node, 'set', this);
68     },
70     /**
71     * @method destroy
72     * @private
73     */
74     destroy: function(){
75         // Nothing to do, but things are happier with it here
76     }
77     
78 }, {
79     
80     /**
81     * Attribute configuration.
82     *
83     * @property ATTRS
84     * @type {Object}
85     * @private
86     * @static
87     */
88     ATTRS: Y.merge(Y.ButtonCore.ATTRS),
89     
90     /**
91     * Name of this component.
92     *
93     * @property NAME
94     * @type String
95     * @static
96     */
97     NAME: 'buttonPlugin',
98     
99     /**
100     * Namespace of this component.
101     *
102     * @property NS
103     * @type String
104     * @static
105     */
106     NS: 'button'
107     
111 * @method createNode
112 * @description A factory that plugs a Y.Node instance with Y.Plugin.Button
113 * @param node {Object}
114 * @param config {Object}
115 * @returns {Object} A plugged Y.Node instance
116 * @public
118 ButtonPlugin.createNode = function(node, config) {
119     var template;
121     if (node && !config) {
122         if (! (node.nodeType || node.getDOMNode || typeof node == 'string')) {
123             config = node;
124             node = config.srcNode;
125         }
126     }
128     config   = config || {};
129     template = config.template || Y.Plugin.Button.prototype.TEMPLATE;
130     node     = node || config.srcNode || Y.DOM.create(template);
132     return Y.one(node).plug(Y.Plugin.Button, config);
135 Y.namespace('Plugin').Button = ButtonPlugin;
138 }, '3.5.1' ,{requires:['button-core', 'cssbutton', 'node-pluginhost']});