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