~michael.nelson/ubuntu-webcatalog/1267731-import-sca-apps-error

« back to all changes in this revision

Viewing changes to src/webcatalog/static/yui/3.10.3/build/io-form/io-form.js

  • Committer: Tarmac
  • Author(s): Stephen Stewart
  • Date: 2013-06-26 09:19:32 UTC
  • mfrom: (184.1.4 ubuntu-global-nav)
  • Revision ID: tarmac-20130626091932-8urtuli368k8p7ds
[r=beuno,jonas-drange] add ubuntu global nav to apps.ubuntu.com

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.10.3 (build 2fb5187)
 
3
Copyright 2013 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
 
 
8
YUI.add('io-form', function (Y, NAME) {
 
9
 
 
10
/**
 
11
* Extends IO to enable HTML form data serialization, when specified
 
12
* in the transaction's configuration object.
 
13
* @module io
 
14
* @submodule io-form
 
15
* @for IO
 
16
*/
 
17
 
 
18
var eUC = encodeURIComponent;
 
19
 
 
20
/**
 
21
 * Enumerate through an HTML form's elements collection
 
22
 * and return a string comprised of key-value pairs.
 
23
 *
 
24
 * @method stringify
 
25
 * @static
 
26
 * @param {Node|String} form YUI form node or HTML form id
 
27
 * @param {Object} [options] Configuration options.
 
28
 * @param {Boolean} [options.useDisabled=false] Whether to include disabled fields.
 
29
 * @param {Object|String} [options.extra] Extra values to include. May be a query string or an object with key/value pairs.
 
30
 * @return {String}
 
31
 */
 
32
Y.IO.stringify = function(form, options) {
 
33
    options = options || {};
 
34
 
 
35
    var s = Y.IO.prototype._serialize({
 
36
        id: form,
 
37
        useDisabled: options.useDisabled
 
38
    },
 
39
    options.extra && typeof options.extra === 'object' ? Y.QueryString.stringify(options.extra) : options.extra);
 
40
 
 
41
    return s;
 
42
};
 
43
 
 
44
Y.mix(Y.IO.prototype, {
 
45
   /**
 
46
    * Enumerate through an HTML form's elements collection
 
47
    * and return a string comprised of key-value pairs.
 
48
    *
 
49
    * @method _serialize
 
50
    * @private
 
51
    * @param {Object} c
 
52
    * @param {String|Element} c.id YUI form node or HTML form id
 
53
    * @param {Boolean} c.useDisabled `true` to include disabled fields
 
54
    * @param {String} s Key-value data defined in the configuration object.
 
55
    * @return {String}
 
56
    */
 
57
    _serialize: function(c, s) {
 
58
        var data = [],
 
59
            df = c.useDisabled || false,
 
60
            item = 0,
 
61
            id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
 
62
            e, f, n, v, d, i, il, j, jl, o;
 
63
 
 
64
        if (!id) {
 
65
            id = Y.guid('io:');
 
66
            c.id.setAttribute('id', id);
 
67
        }
 
68
 
 
69
        f = Y.config.doc.getElementById(id);
 
70
 
 
71
        if (!f || !f.elements) {
 
72
            return s || '';
 
73
        }
 
74
 
 
75
        // Iterate over the form elements collection to construct the
 
76
        // label-value pairs.
 
77
        for (i = 0, il = f.elements.length; i < il; ++i) {
 
78
            e = f.elements[i];
 
79
            d = e.disabled;
 
80
            n = e.name;
 
81
 
 
82
            if (df ? n : n && !d) {
 
83
                n = eUC(n) + '=';
 
84
                v = eUC(e.value);
 
85
 
 
86
                switch (e.type) {
 
87
                    // Safari, Opera, FF all default options.value from .text if
 
88
                    // value attribute not specified in markup
 
89
                    case 'select-one':
 
90
                        if (e.selectedIndex > -1) {
 
91
                            o = e.options[e.selectedIndex];
 
92
                            data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
 
93
                        }
 
94
                        break;
 
95
                    case 'select-multiple':
 
96
                        if (e.selectedIndex > -1) {
 
97
                            for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
 
98
                                o = e.options[j];
 
99
                                if (o.selected) {
 
100
                                  data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
 
101
                                }
 
102
                            }
 
103
                        }
 
104
                        break;
 
105
                    case 'radio':
 
106
                    case 'checkbox':
 
107
                        if (e.checked) {
 
108
                            data[item++] = n + v;
 
109
                        }
 
110
                        break;
 
111
                    case 'file':
 
112
                        // stub case as XMLHttpRequest will only send the file path as a string.
 
113
                    case undefined:
 
114
                        // stub case for fieldset element which returns undefined.
 
115
                    case 'reset':
 
116
                        // stub case for input type reset button.
 
117
                    case 'button':
 
118
                        // stub case for input type button elements.
 
119
                        break;
 
120
                    case 'submit':
 
121
                    default:
 
122
                        data[item++] = n + v;
 
123
                }
 
124
            }
 
125
        }
 
126
 
 
127
        if (s) {
 
128
            data[item++] = s;
 
129
        }
 
130
 
 
131
        return data.join('&');
 
132
    }
 
133
}, true);
 
134
 
 
135
 
 
136
}, '3.10.3', {"requires": ["io-base", "node-base"]});