1 import jQuery
from "./core.js";
2 import toType
from "./core/toType.js";
3 import rcheckableType
from "./var/rcheckableType.js";
5 import "./core/init.js";
6 import "./traversing.js"; // filter
7 import "./attributes/prop.js";
12 rsubmitterTypes
= /^(?:submit|button|image|reset|file)$/i,
13 rsubmittable
= /^(?:input|select|textarea|keygen)/i;
15 function buildParams( prefix
, obj
, traditional
, add
) {
18 if ( Array
.isArray( obj
) ) {
20 // Serialize array item.
21 jQuery
.each( obj
, function( i
, v
) {
22 if ( traditional
|| rbracket
.test( prefix
) ) {
24 // Treat each array item as a scalar.
29 // Item is non-scalar (array or object), encode its numeric index.
31 prefix
+ "[" + ( typeof v
=== "object" && v
!= null ? i
: "" ) + "]",
39 } else if ( !traditional
&& toType( obj
) === "object" ) {
41 // Serialize object item.
43 buildParams( prefix
+ "[" + name
+ "]", obj
[ name
], traditional
, add
);
48 // Serialize scalar item.
53 // Serialize an array of form elements or a set of
54 // key/values into a query string
55 jQuery
.param = function( a
, traditional
) {
58 add = function( key
, valueOrFunction
) {
60 // If value is a function, invoke it and use its return value
61 var value
= typeof valueOrFunction
=== "function" ?
65 s
[ s
.length
] = encodeURIComponent( key
) + "=" +
66 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;
104 } ).filter( function() {
105 var type
= this.type
;
107 // Use .is( ":disabled" ) so that fieldset[disabled] works
108 return this.name
&& !jQuery( this ).is( ":disabled" ) &&
109 rsubmittable
.test( this.nodeName
) && !rsubmitterTypes
.test( type
) &&
110 ( this.checked
|| !rcheckableType
.test( type
) );
111 } ).map( function( _i
, elem
) {
112 var val
= jQuery( this ).val();
118 if ( Array
.isArray( val
) ) {
119 return jQuery
.map( val
, function( val
) {
120 return { name
: elem
.name
, value
: val
.replace( rCRLF
, "\r\n" ) };
124 return { name
: elem
.name
, value
: val
.replace( rCRLF
, "\r\n" ) };
129 export default jQuery
;