~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/build/io-form/io-form-debug.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.5.0 (build 5089)
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
 
        Y.log('HTML form serialized. The value is: ' + data.join('&'), 'info', 'io');
97
 
        return s ? data.join('&') + "&" + s : data.join('&');
98
 
    }
99
 
}, true);
100
 
 
101
 
 
102
 
}, '3.5.0' ,{requires:['io-base','node-base']});