1 | define([
|
2 | "./core",
|
3 | "./manipulation/var/rcheckableType",
|
4 | "./core/init",
|
5 | "./traversing",
|
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 | jQuery.each( obj, function( i, v ) {
|
21 | if ( traditional || rbracket.test( prefix ) ) {
|
22 |
|
23 | add( prefix, v );
|
24 |
|
25 | } else {
|
26 |
|
27 | buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
|
28 | }
|
29 | });
|
30 |
|
31 | } else if ( !traditional && jQuery.type( obj ) === "object" ) {
|
32 |
|
33 | for ( name in obj ) {
|
34 | buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
35 | }
|
36 |
|
37 | } else {
|
38 |
|
39 | add( prefix, obj );
|
40 | }
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 | jQuery.param = function( a, traditional ) {
|
46 | var prefix,
|
47 | s = [],
|
48 | add = function( key, value ) {
|
49 |
|
50 | value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
|
51 | s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
52 | };
|
53 |
|
54 |
|
55 | if ( traditional === undefined ) {
|
56 | traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
|
57 | }
|
58 |
|
59 |
|
60 | if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
61 |
|
62 | jQuery.each( a, function() {
|
63 | add( this.name, this.value );
|
64 | });
|
65 |
|
66 | } else {
|
67 |
|
68 |
|
69 | for ( prefix in a ) {
|
70 | buildParams( prefix, a[ prefix ], traditional, add );
|
71 | }
|
72 | }
|
73 |
|
74 |
|
75 | return s.join( "&" ).replace( r20, "+" );
|
76 | };
|
77 |
|
78 | jQuery.fn.extend({
|
79 | serialize: function() {
|
80 | return jQuery.param( this.serializeArray() );
|
81 | },
|
82 | serializeArray: function() {
|
83 | return this.map(function() {
|
84 |
|
85 | var elements = jQuery.prop( this, "elements" );
|
86 | return elements ? jQuery.makeArray( elements ) : this;
|
87 | })
|
88 | .filter(function() {
|
89 | var type = this.type;
|
90 |
|
91 |
|
92 | return this.name && !jQuery( this ).is( ":disabled" ) &&
|
93 | rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
|
94 | ( this.checked || !rcheckableType.test( type ) );
|
95 | })
|
96 | .map(function( i, elem ) {
|
97 | var val = jQuery( this ).val();
|
98 |
|
99 | return val == null ?
|
100 | null :
|
101 | jQuery.isArray( val ) ?
|
102 | jQuery.map( val, function( val ) {
|
103 | return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
104 | }) :
|
105 | { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
106 | }).get();
|
107 | }
|
108 | });
|
109 |
|
110 | return jQuery;
|
111 | });
|