-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuery.formToObject.min.js
12 lines (12 loc) · 1.58 KB
/
jQuery.formToObject.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/**
* Serializes forms to objects in the same way PHP would do when given get/post data.
* This is intended to be as close to the W3C standards as possible.
* Reference: http://dev.w3.org/html5/spec/single-page.html#constructing-the-form-data-set
*
* @author Beanow
* @company Tuxion
* @email [email protected]
* @licence: MIT
* @link: https://github.com/Tuxion/jQuery.formToObject
*/
(function(a){a.fn.formToObject=function(f){var b={},e=/\]\[|\[|\]/g,d=/^[0-9]+$/,f=f?f.toString():null;var c=function(k){if(a(k).is("[type=file]")){var j=a(k)[0].files,g=[];for(var h=0;h<j.length;h++){g.push({name:j[h].name,type:j[h].type,size:j[h].size})}return g}return a(k).val()};if(a(this).find(":input:enabled, :input[type=hidden]").eq(0).is("[type=text][name=isindex]")){return[a(this).find(":input:enabled").eq(0).val()]}a(this).find(":input:enabled, :input[type=hidden]").each(function(){var o=a(this);if(o.is("[type=button], [type=submit], [type=image]")&&(f?o.is(':not([name="'+f+'"])'):true)){return true}if(o.is("[type=checkbox]:not(:checked), [type=radio]:not(:checked)")){return true}if(!o.attr("name")||o.attr("name")==""){return true}if(o.is("[type=hidden][name=_charset_]")){a.extend(b,{_charset_:document.characterSet?document.characterSet:document.charset});return true}var n=b,h=o.attr("name").split(e);if(h.length>1&&h[h.length-1]==""){h.pop()}for(var l=0;l<h.length;l++){var m=(h.length==l+1),g=(l==0);if(h[l]==""){if(g){return true}var k=-1;for(var j in n){if(d.test(j)&&parseInt(j,10)>k){k=parseInt(j,10)}}k++;n=(n[k]=m?c(o):{})}else{n=(n[h[l]]=m?c(o):n[h[l]]||{})}}});return b}})(jQuery);