Blame view

app/bower_components/jquery/src/serialize.js 3.1 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
3
4
5
6
7
  	"./core",
  	"./manipulation/var/rcheckableType",
  	"./core/init",
  	"./traversing", // filter
  	"./attributes/prop"
  ], function( jQuery, rcheckableType ) {
87c93a029   Dang YoungWorld   add modal
8
9
10
  "use strict";
  
  var
f986e111b   TRUONG   add libs
11
12
13
14
15
16
17
18
19
20
  	rbracket = /\[\]$/,
  	rCRLF = /\r?
  /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 ) ) {
87c93a029   Dang YoungWorld   add modal
21

f986e111b   TRUONG   add libs
22
23
24
  		// Serialize array item.
  		jQuery.each( obj, function( i, v ) {
  			if ( traditional || rbracket.test( prefix ) ) {
87c93a029   Dang YoungWorld   add modal
25

f986e111b   TRUONG   add libs
26
27
28
29
  				// Treat each array item as a scalar.
  				add( prefix, v );
  
  			} else {
87c93a029   Dang YoungWorld   add modal
30

f986e111b   TRUONG   add libs
31
  				// Item is non-scalar (array or object), encode its numeric index.
87c93a029   Dang YoungWorld   add modal
32
33
34
35
36
37
  				buildParams(
  					prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
  					v,
  					traditional,
  					add
  				);
f986e111b   TRUONG   add libs
38
  			}
87c93a029   Dang YoungWorld   add modal
39
  		} );
f986e111b   TRUONG   add libs
40
41
  
  	} else if ( !traditional && jQuery.type( obj ) === "object" ) {
87c93a029   Dang YoungWorld   add modal
42

f986e111b   TRUONG   add libs
43
44
45
46
47
48
  		// Serialize object item.
  		for ( name in obj ) {
  			buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
  		}
  
  	} else {
87c93a029   Dang YoungWorld   add modal
49

f986e111b   TRUONG   add libs
50
51
52
53
54
55
56
57
58
59
  		// 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 = [],
87c93a029   Dang YoungWorld   add modal
60
  		add = function( key, valueOrFunction ) {
f986e111b   TRUONG   add libs
61

87c93a029   Dang YoungWorld   add modal
62
63
64
65
66
67
68
69
  			// If value is a function, invoke it and use its return value
  			var value = jQuery.isFunction( valueOrFunction ) ?
  				valueOrFunction() :
  				valueOrFunction;
  
  			s[ s.length ] = encodeURIComponent( key ) + "=" +
  				encodeURIComponent( value == null ? "" : value );
  		};
f986e111b   TRUONG   add libs
70
71
72
  
  	// If an array was passed in, assume that it is an array of form elements.
  	if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
87c93a029   Dang YoungWorld   add modal
73

f986e111b   TRUONG   add libs
74
75
76
  		// Serialize the form elements
  		jQuery.each( a, function() {
  			add( this.name, this.value );
87c93a029   Dang YoungWorld   add modal
77
  		} );
f986e111b   TRUONG   add libs
78
79
  
  	} else {
87c93a029   Dang YoungWorld   add modal
80

f986e111b   TRUONG   add libs
81
82
83
84
85
86
87
88
  		// 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
87c93a029   Dang YoungWorld   add modal
89
  	return s.join( "&" );
f986e111b   TRUONG   add libs
90
  };
87c93a029   Dang YoungWorld   add modal
91
  jQuery.fn.extend( {
f986e111b   TRUONG   add libs
92
93
94
95
  	serialize: function() {
  		return jQuery.param( this.serializeArray() );
  	},
  	serializeArray: function() {
87c93a029   Dang YoungWorld   add modal
96
  		return this.map( function() {
f986e111b   TRUONG   add libs
97
98
99
  			// Can add propHook for "elements" to filter or add form elements
  			var elements = jQuery.prop( this, "elements" );
  			return elements ? jQuery.makeArray( elements ) : this;
87c93a029   Dang YoungWorld   add modal
100
101
  		} )
  		.filter( function() {
f986e111b   TRUONG   add libs
102
  			var type = this.type;
87c93a029   Dang YoungWorld   add modal
103
104
  
  			// Use .is( ":disabled" ) so that fieldset[disabled] works
f986e111b   TRUONG   add libs
105
106
107
  			return this.name && !jQuery( this ).is( ":disabled" ) &&
  				rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
  				( this.checked || !rcheckableType.test( type ) );
87c93a029   Dang YoungWorld   add modal
108
109
  		} )
  		.map( function( i, elem ) {
f986e111b   TRUONG   add libs
110
  			var val = jQuery( this ).val();
87c93a029   Dang YoungWorld   add modal
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  			if ( val == null ) {
  				return null;
  			}
  
  			if ( jQuery.isArray( val ) ) {
  				return jQuery.map( val, function( val ) {
  					return { name: elem.name, value: val.replace( rCRLF, "\r
  " ) };
  				} );
  			}
  
  			return { name: elem.name, value: val.replace( rCRLF, "\r
  " ) };
  		} ).get();
f986e111b   TRUONG   add libs
125
  	}
87c93a029   Dang YoungWorld   add modal
126
  } );
f986e111b   TRUONG   add libs
127
128
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
129
  } );