kollapsminoriteten/wp-includes/js/jquery/jquery.serialize-object.js

32 lines
769 B
JavaScript
Raw Normal View History

2019-11-02 10:38:58 +01:00
/*!
2021-04-27 08:32:47 +02:00
* jQuery serializeObject - v0.2-wp - 1/20/2010
2019-11-02 10:38:58 +01:00
* http://benalman.com/projects/jquery-misc-plugins/
2021-04-27 08:32:47 +02:00
*
2019-11-02 10:38:58 +01:00
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Whereas .serializeArray() serializes a form into an array, .serializeObject()
// serializes a form into an (arguably more useful) object.
(function($,undefined){
'$:nomunge'; // Used by YUI compressor.
2021-04-27 08:32:47 +02:00
2019-11-02 10:38:58 +01:00
$.fn.serializeObject = function(){
var obj = {};
2021-04-27 08:32:47 +02:00
2019-11-02 10:38:58 +01:00
$.each( this.serializeArray(), function(i,o){
var n = o.name,
v = o.value;
2021-04-27 08:32:47 +02:00
2019-11-02 10:38:58 +01:00
obj[n] = obj[n] === undefined ? v
2021-04-27 08:32:47 +02:00
: Array.isArray( obj[n] ) ? obj[n].concat( v )
2019-11-02 10:38:58 +01:00
: [ obj[n], v ];
});
2021-04-27 08:32:47 +02:00
2019-11-02 10:38:58 +01:00
return obj;
};
2021-04-27 08:32:47 +02:00
2019-11-02 10:38:58 +01:00
})(jQuery);