wp/wp-includes/js/jquery/jquery.serialize-object.js
changeset 18 be944660c56a
parent 0 d970ebf37754
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     1 /*!
     1 /*!
     2  * jQuery serializeObject - v0.2 - 1/20/2010
     2  * jQuery serializeObject - v0.2-wp - 1/20/2010
     3  * http://benalman.com/projects/jquery-misc-plugins/
     3  * http://benalman.com/projects/jquery-misc-plugins/
     4  * 
     4  *
     5  * Copyright (c) 2010 "Cowboy" Ben Alman
     5  * Copyright (c) 2010 "Cowboy" Ben Alman
     6  * Dual licensed under the MIT and GPL licenses.
     6  * Dual licensed under the MIT and GPL licenses.
     7  * http://benalman.com/about/license/
     7  * http://benalman.com/about/license/
     8  */
     8  */
     9 
     9 
    10 // Whereas .serializeArray() serializes a form into an array, .serializeObject()
    10 // Whereas .serializeArray() serializes a form into an array, .serializeObject()
    11 // serializes a form into an (arguably more useful) object.
    11 // serializes a form into an (arguably more useful) object.
    12 
    12 
    13 (function($,undefined){
    13 (function($,undefined){
    14   '$:nomunge'; // Used by YUI compressor.
    14   '$:nomunge'; // Used by YUI compressor.
    15   
    15 
    16   $.fn.serializeObject = function(){
    16   $.fn.serializeObject = function(){
    17     var obj = {};
    17     var obj = {};
    18     
    18 
    19     $.each( this.serializeArray(), function(i,o){
    19     $.each( this.serializeArray(), function(i,o){
    20       var n = o.name,
    20       var n = o.name,
    21         v = o.value;
    21         v = o.value;
    22         
    22 
    23         obj[n] = obj[n] === undefined ? v
    23         obj[n] = obj[n] === undefined ? v
    24           : $.isArray( obj[n] ) ? obj[n].concat( v )
    24           : Array.isArray( obj[n] ) ? obj[n].concat( v )
    25           : [ obj[n], v ];
    25           : [ obj[n], v ];
    26     });
    26     });
    27     
    27 
    28     return obj;
    28     return obj;
    29   };
    29   };
    30   
    30 
    31 })(jQuery);
    31 })(jQuery);