scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
125 | office | 1 | define([ |
58 | office | 2 | "./core", |
3 | "./manipulation/var/rcheckableType", |
||
4 | "./core/init", |
||
5 | "./traversing", // filter |
||
6 | "./attributes/prop" |
||
7 | ], function( jQuery, rcheckableType ) { |
||
8 | |||
125 | office | 9 | var r20 = /%20/g, |
58 | office | 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 | // Serialize array item. |
||
20 | jQuery.each( obj, function( i, v ) { |
||
21 | if ( traditional || rbracket.test( prefix ) ) { |
||
22 | // Treat each array item as a scalar. |
||
23 | add( prefix, v ); |
||
24 | |||
25 | } else { |
||
26 | // Item is non-scalar (array or object), encode its numeric index. |
||
125 | office | 27 | buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add ); |
58 | office | 28 | } |
125 | office | 29 | }); |
58 | office | 30 | |
31 | } else if ( !traditional && jQuery.type( obj ) === "object" ) { |
||
32 | // Serialize object item. |
||
33 | for ( name in obj ) { |
||
34 | buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); |
||
35 | } |
||
36 | |||
37 | } else { |
||
38 | // Serialize scalar item. |
||
39 | add( prefix, obj ); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | // Serialize an array of form elements or a set of |
||
44 | // key/values into a query string |
||
45 | jQuery.param = function( a, traditional ) { |
||
46 | var prefix, |
||
47 | s = [], |
||
125 | office | 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 ); |
||
51 | s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value ); |
||
52 | }; |
||
58 | office | 53 | |
125 | office | 54 | // Set traditional to true for jQuery <= 1.3.2 behavior. |
55 | if ( traditional === undefined ) { |
||
56 | traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional; |
||
57 | } |
||
58 | office | 58 | |
59 | // If an array was passed in, assume that it is an array of form elements. |
||
60 | if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { |
||
61 | // Serialize the form elements |
||
62 | jQuery.each( a, function() { |
||
63 | add( this.name, this.value ); |
||
125 | office | 64 | }); |
58 | office | 65 | |
66 | } else { |
||
67 | // If traditional, encode the "old" way (the way 1.3.2 or older |
||
68 | // did it), otherwise encode params recursively. |
||
69 | for ( prefix in a ) { |
||
70 | buildParams( prefix, a[ prefix ], traditional, add ); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | // Return the resulting serialization |
||
125 | office | 75 | return s.join( "&" ).replace( r20, "+" ); |
58 | office | 76 | }; |
77 | |||
125 | office | 78 | jQuery.fn.extend({ |
58 | office | 79 | serialize: function() { |
80 | return jQuery.param( this.serializeArray() ); |
||
81 | }, |
||
82 | serializeArray: function() { |
||
125 | office | 83 | return this.map(function() { |
58 | office | 84 | // Can add propHook for "elements" to filter or add form elements |
85 | var elements = jQuery.prop( this, "elements" ); |
||
86 | return elements ? jQuery.makeArray( elements ) : this; |
||
125 | office | 87 | }) |
88 | .filter(function() { |
||
58 | office | 89 | var type = this.type; |
90 | |||
91 | // Use .is( ":disabled" ) so that fieldset[disabled] works |
||
92 | return this.name && !jQuery( this ).is( ":disabled" ) && |
||
93 | rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && |
||
94 | ( this.checked || !rcheckableType.test( type ) ); |
||
125 | office | 95 | }) |
96 | .map(function( i, elem ) { |
||
58 | office | 97 | var val = jQuery( this ).val(); |
98 | |||
125 | office | 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(); |
||
58 | office | 107 | } |
125 | office | 108 | }); |
58 | office | 109 | |
110 | return jQuery; |
||
125 | office | 111 | }); |