3 "./manipulation/var/rcheckableType",
5 "./traversing", // filter
7 ], function( jQuery, rcheckableType ) {
12 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
13 rsubmittable = /^(?:input|select|textarea|keygen)/i;
15 function buildParams( prefix, obj, traditional, add ) {
18 if ( jQuery.isArray( obj ) ) {
19 // Serialize array item.
20 jQuery.each( obj, function( i, v ) {
21 if ( traditional || rbracket.test( prefix ) ) {
22 // Treat each array item as a scalar.
26 // Item is non-scalar (array or object), encode its numeric index.
28 prefix + "[" + ( typeof v === "object" ? i : "" ) + "]",
36 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
37 // Serialize object item.
39 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
43 // Serialize scalar item.
48 // Serialize an array of form elements or a set of
49 // key/values into a query string
50 jQuery.param = function( a, traditional ) {
53 add = function( key, value ) {
54 // If value is a function, invoke it and return its value
55 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
56 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
59 // Set traditional to true for jQuery <= 1.3.2 behavior.
60 if ( traditional === undefined ) {
61 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
64 // If an array was passed in, assume that it is an array of form elements.
65 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
66 // Serialize the form elements
67 jQuery.each( a, function() {
68 add( this.name, this.value );
72 // If traditional, encode the "old" way (the way 1.3.2 or older
73 // did it), otherwise encode params recursively.
75 buildParams( prefix, a[ prefix ], traditional, add );
79 // Return the resulting serialization
80 return s.join( "&" ).replace( r20, "+" );
84 serialize: function() {
85 return jQuery.param( this.serializeArray() );
87 serializeArray: function() {
88 return this.map(function() {
89 // Can add propHook for "elements" to filter or add form elements
90 var elements = jQuery.prop( this, "elements" );
91 return elements ? jQuery.makeArray( elements ) : this;
96 // Use .is( ":disabled" ) so that fieldset[disabled] works
97 return this.name && !jQuery( this ).is( ":disabled" ) &&
98 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
99 ( this.checked || !rcheckableType.test( type ) );
101 .map(function( i, elem ) {
102 var val = jQuery( this ).val();
106 jQuery.isArray( val ) ?
107 jQuery.map( val, function( val ) {
108 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
110 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };