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

https://bitbucket.org/skyarch-iijima/wordpress · JavaScript · 31 lines · 14 code · 7 blank · 10 comment · 0 complexity · d15c29a18d9ffa8b9b4ae86c3c0cfa22 MD5 · raw file

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