| 1 | define( [
|
| 2 | "./core",
|
| 3 | "./core/toType",
|
| 4 | "./var/rcheckableType",
|
| 5 | "./var/isFunction",
|
| 6 | "./core/init",
|
| 7 | "./traversing",
|
| 8 | "./attributes/prop"
|
| 9 | ], function( jQuery, toType, rcheckableType, isFunction ) {
|
| 10 |
|
| 11 | "use strict";
|
| 12 |
|
| 13 | var
|
| 14 | rbracket = /\[\]$/,
|
| 15 | rCRLF = /\r?\n/g,
|
| 16 | rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
| 17 | rsubmittable = /^(?:input|select|textarea|keygen)/i;
|
| 18 |
|
| 19 | function buildParams( prefix, obj, traditional, add ) {
|
| 20 | var name;
|
| 21 |
|
| 22 | if ( Array.isArray( obj ) ) {
|
| 23 |
|
| 24 |
|
| 25 | jQuery.each( obj, function( i, v ) {
|
| 26 | if ( traditional || rbracket.test( prefix ) ) {
|
| 27 |
|
| 28 |
|
| 29 | add( prefix, v );
|
| 30 |
|
| 31 | } else {
|
| 32 |
|
| 33 |
|
| 34 | buildParams(
|
| 35 | prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
|
| 36 | v,
|
| 37 | traditional,
|
| 38 | add
|
| 39 | );
|
| 40 | }
|
| 41 | } );
|
| 42 |
|
| 43 | } else if ( !traditional && toType( obj ) === "object" ) {
|
| 44 |
|
| 45 |
|
| 46 | for ( name in obj ) {
|
| 47 | buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
| 48 | }
|
| 49 |
|
| 50 | } else {
|
| 51 |
|
| 52 |
|
| 53 | add( prefix, obj );
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 | jQuery.param = function( a, traditional ) {
|
| 60 | var prefix,
|
| 61 | s = [],
|
| 62 | add = function( key, valueOrFunction ) {
|
| 63 |
|
| 64 |
|
| 65 | var value = isFunction( valueOrFunction ) ?
|
| 66 | valueOrFunction() :
|
| 67 | valueOrFunction;
|
| 68 |
|
| 69 | s[ s.length ] = encodeURIComponent( key ) + "=" +
|
| 70 | encodeURIComponent( value == null ? "" : value );
|
| 71 | };
|
| 72 |
|
| 73 | if ( a == null ) {
|
| 74 | return "";
|
| 75 | }
|
| 76 |
|
| 77 |
|
| 78 | if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
| 79 |
|
| 80 |
|
| 81 | jQuery.each( a, function() {
|
| 82 | add( this.name, this.value );
|
| 83 | } );
|
| 84 |
|
| 85 | } else {
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 | for ( prefix in a ) {
|
| 90 | buildParams( prefix, a[ prefix ], traditional, add );
|
| 91 | }
|
| 92 | }
|
| 93 |
|
| 94 |
|
| 95 | return s.join( "&" );
|
| 96 | };
|
| 97 |
|
| 98 | jQuery.fn.extend( {
|
| 99 | serialize: function() {
|
| 100 | return jQuery.param( this.serializeArray() );
|
| 101 | },
|
| 102 | serializeArray: function() {
|
| 103 | return this.map( function() {
|
| 104 |
|
| 105 |
|
| 106 | var elements = jQuery.prop( this, "elements" );
|
| 107 | return elements ? jQuery.makeArray( elements ) : this;
|
| 108 | } ).filter( function() {
|
| 109 | var type = this.type;
|
| 110 |
|
| 111 |
|
| 112 | return this.name && !jQuery( this ).is( ":disabled" ) &&
|
| 113 | rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
|
| 114 | ( this.checked || !rcheckableType.test( type ) );
|
| 115 | } ).map( function( _i, elem ) {
|
| 116 | var val = jQuery( this ).val();
|
| 117 |
|
| 118 | if ( val == null ) {
|
| 119 | return null;
|
| 120 | }
|
| 121 |
|
| 122 | if ( Array.isArray( val ) ) {
|
| 123 | return jQuery.map( val, function( val ) {
|
| 124 | return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
| 125 | } );
|
| 126 | }
|
| 127 |
|
| 128 | return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
| 129 | } ).get();
|
| 130 | }
|
| 131 | } );
|
| 132 |
|
| 133 | return jQuery;
|
| 134 | } );
|