4 "./manipulation/var/rcheckableType",
7 "./traversing", // filter
9 ], function( jQuery, toType, rcheckableType, isFunction ) {
16 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
17 rsubmittable = /^(?:input|select|textarea|keygen)/i;
19 function buildParams( prefix, obj, traditional, add ) {
22 if ( Array.isArray( obj ) ) {
24 // Serialize array item.
25 jQuery.each( obj, function( i, v ) {
26 if ( traditional || rbracket.test( prefix ) ) {
28 // Treat each array item as a scalar.
33 // Item is non-scalar (array or object), encode its numeric index.
35 prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
43 } else if ( !traditional && toType( obj ) === "object" ) {
45 // Serialize object item.
47 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
52 // Serialize scalar item.
57 // Serialize an array of form elements or a set of
58 // key/values into a query string
59 jQuery.param = function( a, traditional ) {
62 add = function( key, valueOrFunction ) {
64 // If value is a function, invoke it and use its return value
65 var value = isFunction( valueOrFunction ) ?
69 s[ s.length ] = encodeURIComponent( key ) + "=" +
70 encodeURIComponent( value == null ? "" : value );
73 // If an array was passed in, assume that it is an array of form elements.
74 if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
76 // Serialize the form elements
77 jQuery.each( a, function() {
78 add( this.name, this.value );
83 // If traditional, encode the "old" way (the way 1.3.2 or older
84 // did it), otherwise encode params recursively.
86 buildParams( prefix, a[ prefix ], traditional, add );
90 // Return the resulting serialization
95 serialize: function() {
96 return jQuery.param( this.serializeArray() );
98 serializeArray: function() {
99 return this.map( function() {
101 // Can add propHook for "elements" to filter or add form elements
102 var elements = jQuery.prop( this, "elements" );
103 return elements ? jQuery.makeArray( elements ) : this;
105 .filter( function() {
106 var type = this.type;
108 // Use .is( ":disabled" ) so that fieldset[disabled] works
109 return this.name && !jQuery( this ).is( ":disabled" ) &&
110 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
111 ( this.checked || !rcheckableType.test( type ) );
113 .map( function( i, elem ) {
114 var val = jQuery( this ).val();
120 if ( Array.isArray( val ) ) {
121 return jQuery.map( val, function( val ) {
122 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
126 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };