|
|
/** * jQuery serializeObject * @copyright 2014, macek <paulmacek@gmail.com> * @link https://github.com/macek/jquery-serialize-object
* @license BSD * @version 2.5.0 */ (function(n,t){if(typeof define=="function"&&define.amd)define(["exports","jquery"],function(n,i){return t(n,i)});else if(typeof exports!="undefined"){var i=require("jquery");t(exports,i)}else t(n,n.jQuery||n.Zepto||n.ender||n.$)})(this,function(n,t){function i(n,i){function u(n,t,i){return n[t]=i,n}function s(n,t){for(var e=n.match(r.key),i,f;(i=e.pop())!==undefined;)r.push.test(i)?(f=h(n.replace(/\[\]$/,"")),t=u([],f,t)):r.fixed.test(i)?t=u([],i,t):r.named.test(i)&&(t=u({},i,t));return t}function h(n){return e[n]===undefined&&(e[n]=0),e[n]++}function c(n){switch(t('[name="'+n.name+'"]',i).attr("type")){case"checkbox":return n.value==="on"?!0:n.value;default:var r=t('[name="'+n.name+'"]',i).attr("data-type"),u=t('[name="'+n.name+'"]',i).attr("data-name");return r&&u&&u=="int"||r=="pop"?t('[name="'+n.name+'"]',i).data("value")||t('[name="'+n.name+'"]',i).attr("data-value")||n.value:n.value}}function l(t){if(!r.validate.test(t.name))return this;var i=s(t.name,c(t));return f=n.extend(!0,f,i),this}function a(t){if(!n.isArray(t))throw new Error("formSerializer.addPairs expects an Array");for(var i=0,r=t.length;i<r;i++)this.addPair(t[i]);return this}function o(){return f}function v(){return JSON.stringify(o())}var f={},e={};this.addPair=l;this.addPairs=a;this.serialize=o;this.serializeJSON=v}var r={validate:/^[a-z_][a-z0-9_]*(?:\[(?:\d*|[a-z0-9_]+)\])*$/i,key:/[a-z0-9_]+|(?=\[\])/gi,push:/^$/,fixed:/^\d+$/,named:/^[a-z0-9_]+$/i};return i.patterns=r,i.serializeObject=function(){return new i(t,this).addPairs(this.serializeArray()).serialize()},i.serializeJSON=function(){return new i(t,this).addPairs(this.serializeArray()).serializeJSON()},typeof t.fn!="undefined"&&(t.fn.serializeObject=i.serializeObject,t.fn.serializeJSON=i.serializeJSON),n.FormSerializer=i,i});
|