~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/io-form/io-form.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

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('io-form', function(Y) {
 
8
 
 
9
/**
 
10
* Extends IO to enable HTML form data serialization, when specified
 
11
* in the transaction's configuration object.
 
12
* @module io
 
13
* @submodule io-form
 
14
* @for IO
 
15
*/
 
16
 
 
17
var eUC = encodeURIComponent;
 
18
 
 
19
Y.mix(Y.IO.prototype, {
 
20
   /**
 
21
    * Method to enumerate through an HTML form's elements collection
 
22
    * and return a string comprised of key-value pairs.
 
23
    *
 
24
    * @method _serialize
 
25
    * @private
 
26
    * @static
 
27
    * @param {Object} c - YUI form node or HTML form id.
 
28
    * @param {String} s - Key-value data defined in the configuration object.
 
29
    * @return {String}
 
30
    */
 
31
    _serialize: function(c, s) {
 
32
        var data = [],
 
33
            df = c.useDisabled || false,
 
34
            item = 0,
 
35
            id = (typeof c.id === 'string') ? c.id : c.id.getAttribute('id'),
 
36
            e, f, n, v, d, i, il, j, jl, o;
 
37
 
 
38
            if (!id) {
 
39
                id = Y.guid('io:');
 
40
                c.id.setAttribute('id', id);
 
41
            }
 
42
 
 
43
            f = Y.config.doc.getElementById(id);
 
44
 
 
45
        // Iterate over the form elements collection to construct the
 
46
        // label-value pairs.
 
47
        for (i = 0, il = f.elements.length; i < il; ++i) {
 
48
            e = f.elements[i];
 
49
            d = e.disabled;
 
50
            n = e.name;
 
51
 
 
52
            if (df ? n : n && !d) {
 
53
                n = eUC(n) + '=';
 
54
                v = eUC(e.value);
 
55
 
 
56
                switch (e.type) {
 
57
                    // Safari, Opera, FF all default options.value from .text if
 
58
                    // value attribute not specified in markup
 
59
                    case 'select-one':
 
60
                        if (e.selectedIndex > -1) {
 
61
                            o = e.options[e.selectedIndex];
 
62
                            data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
 
63
                        }
 
64
                        break;
 
65
                    case 'select-multiple':
 
66
                        if (e.selectedIndex > -1) {
 
67
                            for (j = e.selectedIndex, jl = e.options.length; j < jl; ++j) {
 
68
                                o = e.options[j];
 
69
                                if (o.selected) {
 
70
                                  data[item++] = n + eUC(o.attributes.value && o.attributes.value.specified ? o.value : o.text);
 
71
                                }
 
72
                            }
 
73
                        }
 
74
                        break;
 
75
                    case 'radio':
 
76
                    case 'checkbox':
 
77
                        if (e.checked) {
 
78
                            data[item++] = n + v;
 
79
                        }
 
80
                        break;
 
81
                    case 'file':
 
82
                        // stub case as XMLHttpRequest will only send the file path as a string.
 
83
                    case undefined:
 
84
                        // stub case for fieldset element which returns undefined.
 
85
                    case 'reset':
 
86
                        // stub case for input type reset button.
 
87
                    case 'button':
 
88
                        // stub case for input type button elements.
 
89
                        break;
 
90
                    case 'submit':
 
91
                    default:
 
92
                        data[item++] = n + v;
 
93
                }
 
94
            }
 
95
        }
 
96
        return s ? data.join('&') + "&" + s : data.join('&');
 
97
    }
 
98
}, true);
 
99
 
 
100
 
 
101
}, '3.5.1' ,{requires:['io-base','node-base']});