Created
April 1, 2009 23:06
-
-
Save isaacs/88939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUI('lang', function (Y) { | |
YAP.toQueryString = function (obj, name) { | |
if (Y.Lang.isNull(obj) || Y.Lang.isUndefined(obj)) { | |
return name ? encodeURIComponent(name) + '=' : ''; | |
} | |
if (Y.Lang.isBoolean(obj)) obj = obj ? 1 : 0; | |
if (Y.Lang.isNumber(obj) || Y.Lang.isString(obj)) { | |
return encodeURIComponent(name) + '=' + encodeURIComponent(obj); | |
} | |
if (Y.Lang.isArray(obj)) { | |
var s = []; | |
name = name+'[]'; | |
for (var i = 0, l = obj.length; i < l; i ++) { | |
s.push( arguments.callee(obj[i], name) ); | |
} | |
return s.join('&'); | |
} | |
// now we know it's an object. | |
var s = []; | |
var begin = name ? name + '[' : ''; | |
var end = name ? ']' : ''; | |
for ( | |
var i in obj | |
) if ( | |
obj.hasOwnProperty(i) && p.substr(p.length - 3, 3) !== '___' | |
) s.push(arguments.callee(obj[i], begin + i + end)); | |
return s.join("&"); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment