Files
cdnjs/ajax/libs/jquery.serializeJSON/1.1.0/jquery.serializeJSON.min.js
T

9 lines
1.1 KiB
JavaScript

/*!
SerializeJSON jQuery plugin.
https://github.com/marioizquierdo/jquery.serializeJSON
version 1.1.0 (Feb 16, 2014)
Copyright (c) 2012 Mario Izquierdo
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*/(function(e){"use strict";e.fn.serializeJSON=function(){var t,n;t={};n=this.serializeArray();e.each(n,function(n,r){var i,s,o;i=r.name;s=r.value;o=e.map(i.split("["),function(e){var t;t=e[e.length-1];return t==="]"?e.substring(0,e.length-1):e});o[0]===""&&o.shift();e.deepSet(t,o,s)});return t};var t=function(e){return e===Object(e)},n=function(e){return!isNaN(parseInt(e,10))&&isFinite(e)};e.deepSet=function(r,i,s){if(!i||i.length===0)throw new Error("ArgumentError: keys param expected to be an array with least one key");var o,u,a,f,l,c;o=i[0];u=i[1];if(u!==undefined&&u!==null){a=i.slice(1);if(o===""){l=r.length-1;c=r[r.length-1];if(t(c)&&!c[u])o=l;else{r.push({});o=l+1}}if(r[o]===undefined){f=u===""||n(u)?[]:{};r[o]=f}e.deepSet(r[o],a,s)}else o===""?r.push(s):r[o]=s}})(jQuery);