~bac/juju-gui/trunkcopy

« back to all changes in this revision

Viewing changes to lib/yui/build/button/button-debug.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

Show diffs side-by-side

added added

removed removed

Lines of Context:
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', function(Y) {
8
 
 
9
 
/**
10
 
* A Button Widget
11
 
*
12
 
* @module button
13
 
* @since 3.5.0
14
 
*/
15
 
 
16
 
var CLASS_NAMES = Y.ButtonCore.CLASS_NAMES,
17
 
    ARIA_STATES = Y.ButtonCore.ARIA_STATES,
18
 
    ARIA_ROLES  = Y.ButtonCore.ARIA_ROLES;
19
 
 
20
 
/**
21
 
* Creates a Button
22
 
*
23
 
* @class Button
24
 
* @extends Widget
25
 
* @param config {Object} Configuration object
26
 
* @constructor
27
 
*/
28
 
function Button(config) {
29
 
    Button.superclass.constructor.apply(this, arguments);
30
 
}
31
 
 
32
 
/* Button extends Widget */
33
 
Y.extend(Button, Y.Widget,  {
34
 
 
35
 
    BOUNDING_TEMPLATE: Y.ButtonCore.prototype.TEMPLATE,
36
 
 
37
 
    CONTENT_TEMPLATE: null,
38
 
 
39
 
    /**
40
 
    * @method initializer
41
 
    * @description Internal init() handler.
42
 
    * @param config {Object} Config object.
43
 
    * @private
44
 
    */
45
 
    initializer: function(config) {
46
 
        this._host = this.get('boundingBox');
47
 
    },
48
 
 
49
 
    /**
50
 
     * bindUI implementation
51
 
     *
52
 
     * @description Hooks up events for the widget
53
 
     * @method bindUI
54
 
     */
55
 
    bindUI: function() {
56
 
        var button = this;
57
 
        button.after('labelChange', button._afterLabelChange);
58
 
        button.after('disabledChange', button._afterDisabledChange);
59
 
    },
60
 
 
61
 
    /**
62
 
     * @method syncUI
63
 
     * @description Updates button attributes
64
 
     */
65
 
    syncUI: function() {
66
 
        var button = this;
67
 
        button._uiSetLabel(button.get('label'));
68
 
        button._uiSetDisabled(button.get('disabled'));
69
 
    },
70
 
 
71
 
    /**
72
 
    * @method _afterLabelChange
73
 
    * @private
74
 
    */
75
 
    _afterLabelChange: function(e) {
76
 
        this._uiSetLabel(e.newVal);
77
 
    },
78
 
 
79
 
    /**
80
 
    * @method _afterDisabledChange
81
 
    * @private
82
 
    */
83
 
    _afterDisabledChange: function(e) {
84
 
        this._uiSetDisabled(e.newVal);
85
 
    }
86
 
 
87
 
}, {
88
 
    // Y.Button static properties
89
 
 
90
 
    /**
91
 
     * The identity of the widget.
92
 
     *
93
 
     * @property NAME
94
 
     * @type String
95
 
     * @default 'button'
96
 
     * @readOnly
97
 
     * @protected
98
 
     * @static
99
 
     */
100
 
    NAME: 'button',
101
 
 
102
 
    /**
103
 
    * Static property used to define the default attribute configuration of
104
 
    * the Widget.
105
 
    *
106
 
    * @property ATTRS
107
 
    * @type {Object}
108
 
    * @protected
109
 
    * @static
110
 
    */
111
 
    ATTRS: {
112
 
        label: {
113
 
            value: Y.ButtonCore.ATTRS.label.value
114
 
        },
115
 
 
116
 
        disabled: {
117
 
            value: false
118
 
        }
119
 
    },
120
 
 
121
 
    /**
122
 
    * @property HTML_PARSER
123
 
    * @type {Object}
124
 
    * @protected
125
 
    * @static
126
 
    */
127
 
    HTML_PARSER: {
128
 
        label: function(node) {
129
 
            this._host = node; // TODO: remove
130
 
            return this._getLabel();
131
 
        },
132
 
 
133
 
        disabled: function(node) {
134
 
            return node.getDOMNode().disabled;
135
 
        }
136
 
    },
137
 
 
138
 
    /**
139
 
     * List of class names used in the ButtonGroup's DOM
140
 
     *
141
 
     * @property CLASS_NAMES
142
 
     * @type Object
143
 
     * @static
144
 
     */
145
 
    CLASS_NAMES: CLASS_NAMES
146
 
});
147
 
 
148
 
Y.mix(Button.prototype, Y.ButtonCore.prototype);
149
 
 
150
 
/**
151
 
* Creates a ToggleButton
152
 
*
153
 
* @class ToggleButton
154
 
* @extends Button
155
 
* @param config {Object} Configuration object
156
 
* @constructor
157
 
*/
158
 
function ToggleButton(config) {
159
 
    Button.superclass.constructor.apply(this, arguments);
160
 
}
161
 
 
162
 
// TODO: move to ButtonCore subclass to enable toggle plugin, widget, etc.
163
 
/* ToggleButton extends Button */
164
 
Y.extend(ToggleButton, Button,  {
165
 
    
166
 
    trigger: 'click',
167
 
    selectedAttrName: '',
168
 
    
169
 
    initializer: function (config) {
170
 
        var button = this,
171
 
            type = button.get('type'),
172
 
            selectedAttrName = (type === "checkbox" ? 'checked' : 'pressed'),
173
 
            selectedState = config[selectedAttrName] || false;
174
 
        
175
 
        // Create the checked/pressed attribute
176
 
        button.addAttr(selectedAttrName, {
177
 
            value: selectedState
178
 
        });
179
 
        
180
 
        button.selectedAttrName = selectedAttrName;
181
 
    },
182
 
    
183
 
    destructor: function () {
184
 
        delete this.selectedAttrName;
185
 
    },
186
 
    
187
 
    /**
188
 
     * @method bindUI
189
 
     * @description Hooks up events for the widget
190
 
     */
191
 
    bindUI: function() {
192
 
         var button = this,
193
 
             cb = button.get('contentBox');
194
 
        
195
 
        ToggleButton.superclass.bindUI.call(button);
196
 
        
197
 
        cb.on(button.trigger, button.toggle, button);
198
 
        button.after(button.selectedAttrName + 'Change', button._afterSelectedChange);
199
 
    },
200
 
 
201
 
    /**
202
 
     * @method syncUI
203
 
     * @description Syncs the UI for the widget
204
 
     */
205
 
    syncUI: function() {
206
 
        var button = this,
207
 
            cb = button.get('contentBox'),
208
 
            type = button.get('type'),
209
 
            ROLES = ToggleButton.ARIA_ROLES,
210
 
            role = (type === 'checkbox' ? ROLES.CHECKBOX : ROLES.TOGGLE),
211
 
            selectedAttrName = button.selectedAttrName;
212
 
 
213
 
        ToggleButton.superclass.syncUI.call(button);
214
 
        
215
 
        cb.set('role', role);
216
 
        button._uiSetSelected(button.get(selectedAttrName));
217
 
    },
218
 
    
219
 
    _afterSelectedChange: function(e){
220
 
        this._uiSetSelected(e.newVal);
221
 
    },
222
 
    
223
 
    /**
224
 
    * @method _uiSetSelected
225
 
    * @private
226
 
    */
227
 
    _uiSetSelected: function(value) {
228
 
        var button = this,
229
 
            cb = button.get('contentBox'),
230
 
            STATES = ToggleButton.ARIA_STATES,
231
 
            type = button.get('type'),
232
 
            ariaState = (type === 'checkbox' ? STATES.CHECKED : STATES.PRESSED);
233
 
        
234
 
        cb.toggleClass(Button.CLASS_NAMES.SELECTED, value);
235
 
        cb.set(ariaState, value);
236
 
    },
237
 
    
238
 
    /**
239
 
    * @method toggle
240
 
    * @description Toggles the selected/pressed/checked state of a ToggleButton
241
 
    * @public
242
 
    */
243
 
    toggle: function() {
244
 
        var button = this;
245
 
        button._set(button.selectedAttrName, !button.get(button.selectedAttrName));
246
 
    }
247
 
 
248
 
}, {
249
 
    
250
 
    /**
251
 
    * The identity of the widget.
252
 
    *
253
 
    * @property NAME
254
 
    * @type {String}
255
 
    * @default 'buttongroup'
256
 
    * @readOnly
257
 
    * @protected
258
 
    * @static
259
 
    */
260
 
    NAME: 'toggleButton',
261
 
    
262
 
    /**
263
 
    * Static property used to define the default attribute configuration of
264
 
    * the Widget.
265
 
    *
266
 
    * @property ATTRS
267
 
    * @type {Object}
268
 
    * @protected
269
 
    * @static
270
 
    */
271
 
    ATTRS: {
272
 
        type: {
273
 
            value: 'toggle',
274
 
            writeOnce: 'initOnly'
275
 
        }
276
 
    },
277
 
    
278
 
    /**
279
 
    * @property HTML_PARSER
280
 
    * @type {Object}
281
 
    * @protected
282
 
    * @static
283
 
    */
284
 
    HTML_PARSER: {
285
 
        checked: function(node) {
286
 
            return node.hasClass(CLASS_NAMES.SELECTED);
287
 
        },
288
 
        pressed: function(node) {
289
 
            return node.hasClass(CLASS_NAMES.SELECTED);
290
 
        }
291
 
    },
292
 
    
293
 
    /**
294
 
    * @property ARIA_STATES
295
 
    * @type {Object}
296
 
    * @protected
297
 
    * @static
298
 
    */
299
 
    ARIA_STATES: ARIA_STATES,
300
 
 
301
 
    /**
302
 
    * @property ARIA_ROLES
303
 
    * @type {Object}
304
 
    * @protected
305
 
    * @static
306
 
    */
307
 
    ARIA_ROLES: ARIA_ROLES,
308
 
 
309
 
    /**
310
 
     * Array of static constants used to identify the classnames applied to DOM nodes
311
 
     *
312
 
     * @property CLASS_NAMES
313
 
     * @type Object
314
 
     * @static
315
 
     */
316
 
    CLASS_NAMES: CLASS_NAMES
317
 
    
318
 
});
319
 
 
320
 
// Export
321
 
Y.Button = Button;
322
 
Y.ToggleButton = ToggleButton;
323
 
 
324
 
 
325
 
}, '3.5.1' ,{requires:['button-core', 'cssbutton', 'widget']});