2013-08-15 18:15:49 +00:00
|
|
|
define([
|
|
|
|
"./core",
|
|
|
|
"./manipulation/var/rcheckableType",
|
2013-09-10 00:13:01 +00:00
|
|
|
"./core/init",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./traversing", // filter
|
|
|
|
"./attributes/prop"
|
|
|
|
], function( jQuery, rcheckableType ) {
|
|
|
|
|
2012-07-13 07:44:21 +00:00
|
|
|
var r20 = /%20/g,
|
|
|
|
rbracket = /\[\]$/,
|
|
|
|
rCRLF = /\r?\n/g,
|
2013-01-23 17:23:46 +00:00
|
|
|
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
2012-11-26 08:20:43 +00:00
|
|
|
rsubmittable = /^(?:input|select|textarea|keygen)/i;
|
2012-07-13 07:44:21 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
function buildParams( prefix, obj, traditional, add ) {
|
|
|
|
var name;
|
2012-07-13 07:44:21 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
if ( jQuery.isArray( obj ) ) {
|
|
|
|
// Serialize array item.
|
|
|
|
jQuery.each( obj, function( i, v ) {
|
|
|
|
if ( traditional || rbracket.test( prefix ) ) {
|
|
|
|
// Treat each array item as a scalar.
|
|
|
|
add( prefix, v );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Item is non-scalar (array or object), encode its numeric index.
|
|
|
|
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
|
|
|
|
// Serialize object item.
|
|
|
|
for ( name in obj ) {
|
|
|
|
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Serialize scalar item.
|
|
|
|
add( prefix, obj );
|
2012-07-13 07:44:21 +00:00
|
|
|
}
|
2013-09-09 16:13:41 +00:00
|
|
|
}
|
2012-07-13 07:44:21 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Serialize an array of form elements or a set of
|
|
|
|
// key/values into a query string
|
2012-07-13 07:44:21 +00:00
|
|
|
jQuery.param = function( a, traditional ) {
|
|
|
|
var prefix,
|
|
|
|
s = [],
|
|
|
|
add = function( key, value ) {
|
|
|
|
// If value is a function, invoke it and return its value
|
|
|
|
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
|
|
|
|
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set traditional to true for jQuery <= 1.3.2 behavior.
|
|
|
|
if ( traditional === undefined ) {
|
|
|
|
traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an array was passed in, assume that it is an array of form elements.
|
|
|
|
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
|
|
|
// Serialize the form elements
|
|
|
|
jQuery.each( a, function() {
|
|
|
|
add( this.name, this.value );
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// If traditional, encode the "old" way (the way 1.3.2 or older
|
|
|
|
// did it), otherwise encode params recursively.
|
|
|
|
for ( prefix in a ) {
|
|
|
|
buildParams( prefix, a[ prefix ], traditional, add );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the resulting serialization
|
|
|
|
return s.join( "&" ).replace( r20, "+" );
|
|
|
|
};
|
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
jQuery.fn.extend({
|
|
|
|
serialize: function() {
|
|
|
|
return jQuery.param( this.serializeArray() );
|
|
|
|
},
|
|
|
|
serializeArray: function() {
|
2013-09-11 01:08:01 +00:00
|
|
|
return this.map(function() {
|
2013-09-09 16:13:41 +00:00
|
|
|
// Can add propHook for "elements" to filter or add form elements
|
|
|
|
var elements = jQuery.prop( this, "elements" );
|
|
|
|
return elements ? jQuery.makeArray( elements ) : this;
|
|
|
|
})
|
2013-09-11 01:08:01 +00:00
|
|
|
.filter(function() {
|
2013-09-09 16:13:41 +00:00
|
|
|
var type = this.type;
|
2013-09-11 01:08:01 +00:00
|
|
|
|
|
|
|
// Use .is( ":disabled" ) so that fieldset[ disabled ] works
|
2013-09-09 16:13:41 +00:00
|
|
|
return this.name && !jQuery( this ).is( ":disabled" ) &&
|
|
|
|
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
|
|
|
|
( this.checked || !rcheckableType.test( type ) );
|
|
|
|
})
|
2013-09-11 01:08:01 +00:00
|
|
|
.map(function( i, elem ) {
|
2013-09-09 16:13:41 +00:00
|
|
|
var val = jQuery( this ).val();
|
2012-07-13 07:44:21 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
return val == null ?
|
|
|
|
null :
|
|
|
|
jQuery.isArray( val ) ?
|
2013-09-11 01:08:01 +00:00
|
|
|
jQuery.map( val, function( val ) {
|
2013-09-09 16:13:41 +00:00
|
|
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
|
|
|
}) :
|
|
|
|
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
|
|
|
}).get();
|
2012-07-13 07:44:21 +00:00
|
|
|
}
|
2013-09-09 16:13:41 +00:00
|
|
|
});
|
2013-09-09 01:25:27 +00:00
|
|
|
|
|
|
|
return jQuery;
|
2013-08-15 18:15:49 +00:00
|
|
|
});
|