2015-08-16 06:59:58 +00:00
|
|
|
define( [
|
2013-08-15 18:15:49 +00:00
|
|
|
"./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 ) {
|
|
|
|
|
2016-04-25 18:25:08 +00:00
|
|
|
"use strict";
|
|
|
|
|
2015-10-22 18:25:32 +00:00
|
|
|
var
|
2012-07-13 07:44:21 +00:00
|
|
|
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
|
|
|
|
2016-08-14 10:54:16 +00:00
|
|
|
if ( Array.isArray( obj ) ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
// Serialize array item.
|
|
|
|
jQuery.each( obj, function( i, v ) {
|
|
|
|
if ( traditional || rbracket.test( prefix ) ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
// Treat each array item as a scalar.
|
|
|
|
add( prefix, v );
|
|
|
|
|
|
|
|
} else {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
// Item is non-scalar (array or object), encode its numeric index.
|
2014-07-17 17:25:59 +00:00
|
|
|
buildParams(
|
2015-09-07 21:22:56 +00:00
|
|
|
prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
|
2014-07-17 17:25:59 +00:00
|
|
|
v,
|
|
|
|
traditional,
|
|
|
|
add
|
|
|
|
);
|
2013-09-09 16:13:41 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-09-09 16:13:41 +00:00
|
|
|
|
|
|
|
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
// Serialize object item.
|
|
|
|
for ( name in obj ) {
|
|
|
|
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
// 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 = [],
|
2016-04-05 14:54:37 +00:00
|
|
|
add = function( key, valueOrFunction ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2016-04-05 14:54:37 +00:00
|
|
|
// If value is a function, invoke it and use its return value
|
|
|
|
var value = jQuery.isFunction( valueOrFunction ) ?
|
|
|
|
valueOrFunction() :
|
|
|
|
valueOrFunction;
|
|
|
|
|
|
|
|
s[ s.length ] = encodeURIComponent( key ) + "=" +
|
|
|
|
encodeURIComponent( value == null ? "" : value );
|
2012-07-13 07:44:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// If an array was passed in, assume that it is an array of form elements.
|
2016-08-14 10:54:16 +00:00
|
|
|
if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-07-13 07:44:21 +00:00
|
|
|
// Serialize the form elements
|
|
|
|
jQuery.each( a, function() {
|
|
|
|
add( this.name, this.value );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2012-07-13 07:44:21 +00:00
|
|
|
|
|
|
|
} else {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2012-07-13 07:44:21 +00:00
|
|
|
// 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
|
2015-10-22 18:25:32 +00:00
|
|
|
return s.join( "&" );
|
2012-07-13 07:44:21 +00:00
|
|
|
};
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.fn.extend( {
|
2013-09-09 16:13:41 +00:00
|
|
|
serialize: function() {
|
|
|
|
return jQuery.param( this.serializeArray() );
|
|
|
|
},
|
|
|
|
serializeArray: function() {
|
2015-08-16 06:59:58 +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;
|
2015-08-16 06:59:58 +00:00
|
|
|
} )
|
|
|
|
.filter( function() {
|
2013-09-09 16:13:41 +00:00
|
|
|
var type = this.type;
|
2013-09-11 01:08:01 +00:00
|
|
|
|
2013-09-13 15:29:48 +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 ) );
|
2015-08-16 06:59:58 +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
|
|
|
|
2016-07-15 17:42:25 +00:00
|
|
|
if ( val == null ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:54:16 +00:00
|
|
|
if ( Array.isArray( val ) ) {
|
2016-07-15 17:42:25 +00:00
|
|
|
return jQuery.map( val, function( val ) {
|
|
|
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
2015-08-16 06:59:58 +00:00
|
|
|
} ).get();
|
2012-07-13 07:44:21 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-09-09 01:25:27 +00:00
|
|
|
|
|
|
|
return jQuery;
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|