You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

8 lines
1.9 KiB

/**
* 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 e(n,t,i){return n[t]=i,n}function s(n,t){for(var f=n.match(r.key),i,u;(i=f.pop())!==undefined;)r.push.test(i)?(u=h(n.replace(/\[\]$/,"")),t=e([],u,t)):r.fixed.test(i)?t=e([],i,t):r.named.test(i)&&(t=e({},i,t));return t}function h(n){return f[n]===undefined&&(f[n]=0),f[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 u=n.extend(!0,u,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 u}function v(){return JSON.stringify(o())}var u={},f={};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});