-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.doydoyclone.min.js
1 lines (1 loc) · 3.08 KB
/
jquery.doydoyclone.min.js
1
(function(a){var m=0,k=null,r="id_doydoy_clone_",h=[],p=[];a.fn.doydoyGetCounter=function(){return m};a.fn.doydoyGetAllClones=function(){return h};a.fn.doydoyGetLastClones=function(){return p};a.fn.doydoyGetLastNewId=function(){return k};a.fn.doydoySetPrefixNewId=function(a){r=a;return this};a.fn.initAllClonesList=function(){h=[];return this};a.fn.doydoyCloneAfter=function(b){b=a.extend(b,{method:"after"});return this.doydoyClone(b)};a.fn.doydoyCloneBefore=function(b){b=a.extend(b,{method:"before"}); return this.doydoyClone(b)};a.fn.doydoyCloneAppend=function(b){b=a.extend(b,{method:"append"});return this.doydoyClone(b)};a.fn.doydoyClonePrepend=function(b){b=a.extend(b,{method:"prepend"});return this.doydoyClone(b)};a.fn.doydoyClone=function(b){var t="after";b=a.extend({method:"",target:"",impact_name:!0,impact_for:!0,new_name:!1,new_all_name:!1,new_all_id:!1,prefix_new_elt:r},b);b.new_all_name&&(b.new_name=!0);m+=1;switch(b.method){case "after":case "before":case "append":case "prepend":t=b.method; break;default:t="after"}this.each(function(){function s(){return a(u).clone(!0).each(function(){k=l+"_"+d;a(this).attr("id",k);var c="";if(void 0!==a(this).attr("name")){if(c=a(this).attr("name"),b.new_name||b.impact_name)c+="_"+d,a(this).attr("name",c)}else b.new_name&&(c=k,a(this).attr("name",c));void 0!==a(this).attr("for")&&b.impact_for&&a(this).attr("for",a(this).attr("for")+"_"+d);void 0===h['"'+d+'"']&&(h['"'+d+'"']=[]);h['"'+d+'"'].parent={id:k,id_before:l,num_clone:d,name:c,elt:a(this)}; p.parent={id:k,id_before:l,num_clone:d,name:c,elt:a(this)};d+=1})}function r(c){n=0;a("#"+l+"_"+c+" *").each(function(){void 0!==a(this).attr("id")?(q=a(this).attr("id"),f=q+"_"+c,a(this).attr("id",f)):(q="",b.new_all_id?(f=void 0!==a(this).attr("name")?b.prefix_new_elt+a(this).attr("name")+"_"+c:b.prefix_new_elt+a(this).prop("tagName")+"_"+c,a(this).attr("id",f)):f="");if(void 0!==a(this).attr("name")){if(g=a(this).attr("name"),b.new_all_name||b.impact_name)g+="_"+c,a(this).attr("name",g)}else b.new_all_name? (g=""!==f?f:b.prefix_new_elt+a(this).prop("tagName")+"_"+c,a(this).attr("name",g)):g="";void 0!==a(this).attr("for")&&b.impact_for&&a(this).attr("for",a(this).attr("for")+"_"+c);void 0===h['"'+c+'"'].child&&(h['"'+c+'"'].child=[]);h['"'+c+'"'].child[n]={id:f,id_before:q,num_clone:c,name:g,elt:a(this)};c===d-1&&(p.child[n]={id:f,id_before:q,num_clone:c,name:g,elt:a(this)});void 0!==b.each_child_callback&&b.each_child_callback('"'+c+'"',l+"_"+c,n,f);n+=1});void 0!==b.each_callback&&b.each_callback('"'+ c+'"',l+"_"+c)}var l,u=this,d=m,e="",n=0,q="",f="",g="",e="";p=[];k=null;l=void 0===a(this).attr("id")?void 0!==a(this).attr("name")?b.prefix_new_elt+a(this).attr("name"):b.prefix_new_elt+a(this).prop("tagName"):a(this).attr("id");e=""!==b.target?b.target:a(this);switch(t){case "after":a(e).each(function(){a(this).after(s())});break;case "before":a(e).each(function(){a(this).before(s())});break;case "append":a(e).each(function(){a(this).append(s())});break;case "prepend":a(e).each(function(){a(this).prepend(s())})}p.child= [];for(e=m;e<d;e+=1)r(e);m=d-1});void 0!==b.callback&&b.callback();return this}})(jQuery);