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