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