Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('querystring-stringify-simple', function (Y, NAME) {
2
 
3
/*global Y */
4
/**
5
 * <p>Provides Y.QueryString.stringify method for converting objects to Query Strings.
6
 * This is a subset implementation of the full querystring-stringify.</p>
7
 * <p>This module provides the bare minimum functionality (encoding a hash of simple values),
8
 * without the additional support for nested data structures.  Every key-value pair is
9
 * encoded by encodeURIComponent.</p>
10
 * <p>This module provides a minimalistic way for io to handle  single-level objects
11
 * as transaction data.</p>
12
 *
13
 * @module querystring
14
 * @submodule querystring-stringify-simple
15
 */
16
 
17
var QueryString = Y.namespace("QueryString"),
18
    EUC = encodeURIComponent;
19
 
20
 
21
QueryString.stringify = function (obj, c) {
22
    var qs = [],
23
        // Default behavior is false; standard key notation.
24
        s = c && c.arrayKey ? true : false,
25
        key, i, l;
26
 
27
    for (key in obj) {
28
        if (obj.hasOwnProperty(key)) {
29
            if (Y.Lang.isArray(obj[key])) {
30
                for (i = 0, l = obj[key].length; i < l; i++) {
31
                    qs.push(EUC(s ? key + '[]' : key) + '=' + EUC(obj[key][i]));
32
                }
33
            }
34
            else {
35
                qs.push(EUC(key) + '=' + EUC(obj[key]));
36
            }
37
        }
38
    }
39
 
40
    return qs.join('&');
41
};
42
 
43
 
44
}, '3.18.1', {"requires": ["yui-base"]});