~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/button-group/button-group-debug.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
 
YUI.add('button-group', function (Y, NAME) {
3
 
 
4
 
/**
5
 
 * A Widget to create groups of buttons
6
 
 *
7
 
 * @module button-group
8
 
 * @since 3.5.0
9
 
 */
10
 
 
11
 
var CONTENT_BOX = "contentBox",
12
 
    CLICK_EVENT = "click",
13
 
    CLASS_NAMES = Y.ButtonCore.CLASS_NAMES;
14
 
 
15
 
/**
16
 
 * Creates a ButtonGroup
17
 
 *
18
 
 * @class ButtonGroup
19
 
 * @extends Widget
20
 
 * @param config {Object} Configuration object
21
 
 * @constructor
22
 
 */
23
 
function ButtonGroup() {
24
 
    ButtonGroup.superclass.constructor.apply(this, arguments);
25
 
}
26
 
 
27
 
/* ButtonGroup extends Widget */
28
 
Y.ButtonGroup = Y.extend(ButtonGroup, Y.Widget, {
29
 
 
30
 
    /**
31
 
     * @method renderUI
32
 
     * @description Creates a visual representation of the widget based on existing parameters.
33
 
     * @public
34
 
     */
35
 
    renderUI: function() {
36
 
        this.getButtons().plug(Y.Plugin.Button);
37
 
    },
38
 
 
39
 
    /**
40
 
     * @method bindUI
41
 
     * @description Hooks up events for the widget
42
 
     * @public
43
 
     */
44
 
    bindUI: function() {
45
 
        var group = this,
46
 
            cb = group.get(CONTENT_BOX);
47
 
 
48
 
        cb.delegate(CLICK_EVENT, group._handleClick, Y.ButtonGroup.BUTTON_SELECTOR, group);
49
 
    },
50
 
 
51
 
    /**
52
 
     * @method getButtons
53
 
     * @description Returns all buttons inside this this button group
54
 
     * @public
55
 
     */
56
 
    getButtons: function() {
57
 
        var cb = this.get(CONTENT_BOX);
58
 
 
59
 
        return cb.all(Y.ButtonGroup.BUTTON_SELECTOR);
60
 
    },
61
 
 
62
 
    /**
63
 
     * @method getSelectedButtons
64
 
     * @description Returns all Y.Buttons instances that are selected
65
 
     * @public
66
 
     */
67
 
    getSelectedButtons: function() {
68
 
        var group = this,
69
 
            selected = [],
70
 
            buttons = group.getButtons(),
71
 
            selectedClass = ButtonGroup.CLASS_NAMES.SELECTED;
72
 
 
73
 
        buttons.each(function(node){
74
 
            if (node.hasClass(selectedClass)){
75
 
                selected.push(node);
76
 
            }
77
 
        });
78
 
 
79
 
        return selected;
80
 
    },
81
 
 
82
 
    /**
83
 
     * @method getSelectedValues
84
 
     * @description Returns the values of all Y.Button instances that are selected
85
 
     * @public
86
 
     */
87
 
    getSelectedValues: function() {
88
 
        var selected = this.getSelectedButtons(),
89
 
            values = [],
90
 
            value;
91
 
 
92
 
        Y.Array.each(selected, function(node){
93
 
            value = node.getContent();
94
 
            values.push(value);
95
 
        });
96
 
 
97
 
        return values;
98
 
    },
99
 
 
100
 
    /**
101
 
     * @method _handleClick
102
 
     * @description A delegated click handler for when any button is clicked in the content box
103
 
     * @param e {Object} An event object
104
 
     * @private
105
 
     */
106
 
    _handleClick: function(e){
107
 
        var group = this,
108
 
            clickedNode = e.target.ancestor('.' + ButtonGroup.CLASS_NAMES.BUTTON, true),
109
 
            type = group.get('type'),
110
 
            selectedClass = ButtonGroup.CLASS_NAMES.SELECTED,
111
 
            isSelected = clickedNode.hasClass(selectedClass),
112
 
            buttons;
113
 
 
114
 
        // TODO: Anything for 'push' groups?
115
 
        if (type === 'checkbox') {
116
 
            clickedNode.toggleClass(selectedClass, !isSelected);
117
 
            /**
118
 
             * @event selectionChange
119
 
             * @description fires when any button in the group changes its checked status
120
 
             * @param {Event} the event object. It contains an "originEvent" property
121
 
             * linking to the original DOM event that triggered the selection change
122
 
             */
123
 
            group.fire('selectionChange', {originEvent: e});
124
 
        }
125
 
        else if (type === 'radio' && !isSelected) {
126
 
            buttons = group.getButtons(); // Todo: getSelectedButtons()? Need it to return an arraylist then.
127
 
            buttons.removeClass(selectedClass);
128
 
            clickedNode.addClass(selectedClass);
129
 
            group.fire('selectionChange', {originEvent: e});
130
 
        }
131
 
    }
132
 
 
133
 
}, {
134
 
    // Y.ButtonGroup static properties
135
 
 
136
 
    /**
137
 
     * The identity of the widget.
138
 
     *
139
 
     * @property NAME
140
 
     * @type {String}
141
 
     * @default 'buttongroup'
142
 
     * @readOnly
143
 
     * @protected
144
 
     * @static
145
 
     */
146
 
    NAME: 'buttongroup',
147
 
 
148
 
    /**
149
 
     * Static property used to define the default attribute configuration of
150
 
     * the Widget.
151
 
     *
152
 
     * @property ATTRS
153
 
     * @type {Object}
154
 
     * @protected
155
 
     * @static
156
 
     */
157
 
    ATTRS: {
158
 
 
159
 
        /**
160
 
         * @attribute type
161
 
         * @type String
162
 
         */
163
 
        type: {
164
 
            writeOnce: 'initOnly',
165
 
            value: 'radio'
166
 
        }
167
 
    },
168
 
 
169
 
    /**
170
 
     * List of class names to use for ButtonGroups
171
 
     *
172
 
     * @property CLASS_NAMES
173
 
     * @type {Object}
174
 
     * @static
175
 
     */
176
 
    CLASS_NAMES: CLASS_NAMES,
177
 
    
178
 
    /**
179
 
     * Selector used to find buttons inside a ButtonGroup
180
 
     * @property BUTTON_SELECTOR
181
 
     * @type {String}
182
 
     */
183
 
    BUTTON_SELECTOR: "button, input[type=button], input[type=reset], input[type=submit], input[type=radio], input[type=checkbox]"
184
 
});
185
 
 
186
 
 
187
 
}, '3.9.1', {"requires": ["button-plugin", "cssbutton", "widget"]});