scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 58 Rev 125
Line 1... Line 1...
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 ) {
Line 8... Line 8...
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,
Line 15... Line 13...
15 rsubmittable = /^(?:input|select|textarea|keygen)/i; 13 rsubmittable = /^(?:input|select|textarea|keygen)/i;
16   14  
Line 17... Line 15...
17 function buildParams( prefix, obj, traditional, add ) { 15 function buildParams( prefix, obj, traditional, add ) {
18 var name; -  
19   16 var name;
20 if ( jQuery.isArray( obj ) ) { 17  
21   18 if ( jQuery.isArray( obj ) ) {
22 // Serialize array item. -  
23 jQuery.each( obj, function( i, v ) { 19 // Serialize array item.
24 if ( traditional || rbracket.test( prefix ) ) { 20 jQuery.each( obj, function( i, v ) {
Line 25... Line 21...
25   21 if ( traditional || rbracket.test( prefix ) ) {
26 // Treat each array item as a scalar. -  
27 add( prefix, v ); 22 // Treat each array item as a scalar.
28   -  
29 } else { 23 add( prefix, v );
30   -  
31 // Item is non-scalar (array or object), encode its numeric index. -  
32 buildParams( -  
33 prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]", -  
34 v, 24  
35 traditional, 25 } else {
Line 36... Line 26...
36 add 26 // Item is non-scalar (array or object), encode its numeric index.
37 ); -  
38 } 27 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
39 } ); 28 }
40   29 });
41 } else if ( !traditional && jQuery.type( obj ) === "object" ) { 30  
Line 42... Line 31...
42   31 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
43 // Serialize object item. -  
44 for ( name in obj ) { 32 // Serialize object item.
45 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); 33 for ( name in obj ) {
46 } 34 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
47   35 }
Line 48... Line 36...
48 } else { 36  
49   37 } else {
50 // Serialize scalar item. 38 // Serialize scalar item.
51 add( prefix, obj ); 39 add( prefix, obj );
52 } 40 }
53 } 41 }
54   -  
55 // Serialize an array of form elements or a set of 42  
56 // key/values into a query string 43 // Serialize an array of form elements or a set of
57 jQuery.param = function( a, traditional ) { -  
58 var prefix, -  
59 s = [], -  
60 add = function( key, valueOrFunction ) { 44 // key/values into a query string
61   -  
62 // If value is a function, invoke it and use its return value 45 jQuery.param = function( a, traditional ) {
Line -... Line 46...
-   46 var prefix,
-   47 s = [],
-   48 add = function( key, value ) {
-   49 // If value is a function, invoke it and return its value
-   50 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
63 var value = jQuery.isFunction( valueOrFunction ) ? 51 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
64 valueOrFunction() : 52 };
65 valueOrFunction; -  
66   53  
67 s[ s.length ] = encodeURIComponent( key ) + "=" + 54 // Set traditional to true for jQuery <= 1.3.2 behavior.
68 encodeURIComponent( value == null ? "" : value ); 55 if ( traditional === undefined ) {
69 }; 56 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
Line 70... Line 57...
70   57 }
71 // 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 ) ) ) { 58  
73   59 // If an array was passed in, assume that it is an array of form elements.
74 // Serialize the form elements 60 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
75 jQuery.each( a, function() { 61 // Serialize the form elements
76 add( this.name, this.value ); 62 jQuery.each( a, function() {
77 } ); 63 add( this.name, this.value );
Line 78... Line 64...
78   64 });
79 } else { 65  
80   66 } else {
Line 81... Line 67...
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   -  
88 // Return the resulting serialization 73  
89 return s.join( "&" ); 74 // Return the resulting serialization
90 }; 75 return s.join( "&" ).replace( r20, "+" );
91   76 };
92 jQuery.fn.extend( { 77  
93 serialize: function() { 78 jQuery.fn.extend({
Line 94... Line 79...
94 return jQuery.param( this.serializeArray() ); 79 serialize: function() {
95 }, 80 return jQuery.param( this.serializeArray() );
96 serializeArray: function() { 81 },
97 return this.map( function() { 82 serializeArray: function() {
98   83 return this.map(function() {
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" );
Line 101... Line 86...
101 return elements ? jQuery.makeArray( elements ) : this; 86 return elements ? jQuery.makeArray( elements ) : this;
102 } ) 87 })
103 .filter( function() { -  
104 var type = this.type; -  
105   88 .filter(function() {
106 // Use .is( ":disabled" ) so that fieldset[disabled] works 89 var type = this.type;
107 return this.name && !jQuery( this ).is( ":disabled" ) && 90  
108 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && 91 // Use .is( ":disabled" ) so that fieldset[disabled] works
109 ( this.checked || !rcheckableType.test( type ) ); -  
110 } ) -  
111 .map( function( i, elem ) { 92 return this.name && !jQuery( this ).is( ":disabled" ) &&
112 var val = jQuery( this ).val(); 93 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
113   94 ( this.checked || !rcheckableType.test( type ) );
114 if ( val == null ) { 95 })
Line 115... Line 96...
115 return null; 96 .map(function( i, elem ) {
116 } 97 var val = jQuery( this ).val();