nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / serialize.js
1 define( [
2         "./core",
3         "./manipulation/var/rcheckableType",
4         "./core/init",
5         "./traversing", // filter
6         "./attributes/prop"
7 ], function( jQuery, rcheckableType ) {
8
9 var r20 = /%20/g,
10         rbracket = /\[\]$/,
11         rCRLF = /\r?\n/g,
12         rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
13         rsubmittable = /^(?:input|select|textarea|keygen)/i;
14
15 function buildParams( prefix, obj, traditional, add ) {
16         var name;
17
18         if ( jQuery.isArray( obj ) ) {
19
20                 // Serialize array item.
21                 jQuery.each( obj, function( i, v ) {
22                         if ( traditional || rbracket.test( prefix ) ) {
23
24                                 // Treat each array item as a scalar.
25                                 add( prefix, v );
26
27                         } else {
28
29                                 // Item is non-scalar (array or object), encode its numeric index.
30                                 buildParams(
31                                         prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
32                                         v,
33                                         traditional,
34                                         add
35                                 );
36                         }
37                 } );
38
39         } else if ( !traditional && jQuery.type( obj ) === "object" ) {
40
41                 // Serialize object item.
42                 for ( name in obj ) {
43                         buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
44                 }
45
46         } else {
47
48                 // Serialize scalar item.
49                 add( prefix, obj );
50         }
51 }
52
53 // Serialize an array of form elements or a set of
54 // key/values into a query string
55 jQuery.param = function( a, traditional ) {
56         var prefix,
57                 s = [],
58                 add = function( key, value ) {
59
60                         // If value is a function, invoke it and return its value
61                         value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
62                         s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
63                 };
64
65         // Set traditional to true for jQuery <= 1.3.2 behavior.
66         if ( traditional === undefined ) {
67                 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
68         }
69
70         // If an array was passed in, assume that it is an array of form elements.
71         if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
72
73                 // Serialize the form elements
74                 jQuery.each( a, function() {
75                         add( this.name, this.value );
76                 } );
77
78         } else {
79
80                 // If traditional, encode the "old" way (the way 1.3.2 or older
81                 // did it), otherwise encode params recursively.
82                 for ( prefix in a ) {
83                         buildParams( prefix, a[ prefix ], traditional, add );
84                 }
85         }
86
87         // Return the resulting serialization
88         return s.join( "&" ).replace( r20, "+" );
89 };
90
91 jQuery.fn.extend( {
92         serialize: function() {
93                 return jQuery.param( this.serializeArray() );
94         },
95         serializeArray: function() {
96                 return this.map( function() {
97
98                         // Can add propHook for "elements" to filter or add form elements
99                         var elements = jQuery.prop( this, "elements" );
100                         return elements ? jQuery.makeArray( elements ) : this;
101                 } )
102                 .filter( function() {
103                         var type = this.type;
104
105                         // Use .is( ":disabled" ) so that fieldset[disabled] works
106                         return this.name && !jQuery( this ).is( ":disabled" ) &&
107                                 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
108                                 ( this.checked || !rcheckableType.test( type ) );
109                 } )
110                 .map( function( i, elem ) {
111                         var val = jQuery( this ).val();
112
113                         return val == null ?
114                                 null :
115                                 jQuery.isArray( val ) ?
116                                         jQuery.map( val, function( val ) {
117                                                 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
118                                         } ) :
119                                         { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
120                 } ).get();
121         }
122 } );
123
124 return jQuery;
125 } );