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