1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/**
* jQuery Serialize List
* Copyright (c) 2009 Mike Botsko, Botsko.net LLC
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* Copyright notice and license must remain intact for legal use
* Version .2
*
* Serialize an unordered or ordered list item. Optional ability
* to determine which attributes are included. The serialization
* will be read by PHP as a multidimensional array which you may
* use for saving state.
*
* http://github.com/botskonet/jquery.serialize-list
*/
!function(h){h.fn.serializelist=function(e){var i,r,a,t={attributes:["id"],allow_nest:!0,prepend:"ul",att_regex:!1,is_child:!1},l=h.extend(t,e),s=l.attributes,c="",d=function(e,t){if(!l.att_regex)return t;for(r in l.att_regex)if(l.att_regex[r].att===e)return t.replace(l.att_regex[r].regex,"")};return l.is_child||(l.prepend="&"+l.prepend),this.each(function(n,e){h(e).children().each(function(e,t){if(l.allow_nest||1<s.length)for(var r=0;r<s.length;r++)i=d(s[r],h(t).attr(s[r])),c+=l.prepend+"["+n+"]["+e+"]["+s[r]+"]="+i;else i=d(s[0],h(t).attr(s[0])),c+=l.prepend+"["+n+"]["+e+"]="+i;l.allow_nest&&(a=l.prepend+"["+n+"]["+e+"][children]",h(t).children().each(function(){"UL"!=this.tagName&&"OL"!=this.tagName||(c+=h(this).serializelist({prepend:a,is_child:!0}))})),e++})}),c}}(jQuery);
|