Blame view

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