text: jQuery.fn.repeater=function(a){var b=this,c={template:"",limit:5,items:[{}],saveEvents:"blur change",saveElements:"input, select",addButtonMarkup:"+",removeButtonMarkup:"-",minItemCount:1,callbacks:{save:function(){},beforeAdd:function(){},add:function(){},beforeAddNew:function(){},addNew:function(){},beforeRemove:function(){},remove:function(){},repeaterButtons:function(){return!1}}};return b.options=jQuery.extend(!0,{},c,a),b.elem=jQuery(this),b.items=b.options.items,b.callbacks=b.options.callbacks,b._template=b.options.template,b._baseObj=b.items[0],b.init=function(){return b.stashTemplate(),b.elem.addClass("repeater"),b.refresh(),b.bindEvents(),b},b.bindEvents=function(){b.options.saveEvents=b.getNamespacedEvents(b.options.saveEvents),b.elem.off("click.repeater","a.add-item"),b.elem.on("click.repeater","a.add-item:not(.inactive)",function(){b.addNewItem(this)}),b.elem.off("click.repeater","a.remove-item"),b.elem.on("click.repeater","a.remove-item",function(a){b.removeItem(this)}),b.elem.off(b.options.saveEvents,b.options.saveElements),b.elem.on(b.options.saveEvents,b.options.saveElements,function(){b.save()})},b.stashTemplate=function(){b._template||(b._template=b.elem.html()),b._template=jQuery.trim(b._template)},b.addItem=function(a,c){var d=b.getItemMarkup(a,c),e=jQuery(d).addClass("item-"+c);b.callbacks.beforeAdd(b,e,a,c),b.append(e),b.populateSelects(a,c),b.callbacks.add(b,e,a,c)},b.getItemMarkup=function(a,c){var d=b._template;for(var e in a)a.hasOwnProperty(e)&&(d=d.replace(/{i}/g,c),d=d.replace("{buttons}",b.getRepeaterButtonsMarkup(c)),d=d.replace(new RegExp("{"+e+"}","g"),a[e]));return d},b.getRepeaterButtonsMarkup=function(a){var c=b.callbacks.repeaterButtons(b,a);return c||(c=b.getDefaultButtonsMarkup(a)),c},b.getDefaultButtonsMarkup=function(a){var c=b.items.length>=b.options.limit&&0!==b.options.limit?"inactive":"",d='<a class="add-item '+c+'" data-index="'+a+'">'+b.options.addButtonMarkup+"</a>";return b.items.length>b.options.minItemCount&&(d+='<a class="remove-item" data-index="'+a+'">'+b.options.removeButtonMarkup+"</a>"),'<div class="repeater-buttons">'+d+"</div>"},b.populateSelects=function(a,c){for(var d in a)if(a.hasOwnProperty(d)){var e=b.elem.find("."+d+"_"+c);e.is("select")&&(jQuery.isArray(a[d])?e.val(a[d]):e.find('option[value="'+a[d]+'"]').prop("selected",!0))}},b.addNewItem=function(a,c){var d=b.isElement(a),c=parseInt("undefined"!=typeof c?c:d?jQuery(a).attr("data-index")+1:b.items.length),e=d?b.getBaseObject():a;return b.callbacks.beforeAddNew(b,c),b.items.splice(c,0,e),b.callbacks.addNew(b,c),b.refresh().save(),b},b.removeItem=function(a){var c=b.isElement(a)?jQuery(a).attr("data-index"):a;b.callbacks.beforeRemove(b,c),delete b.items[c],b.callbacks.remove(b,c),b.save().refresh()},b.refresh=function(){b.elem.empty();for(var a=0;a<b.items.length;a++)b.addItem(b.items[a],a);return b},b.save=function(){for(var a=b.getBaseObjectKeys(),c=[],d=0;d<b.items.length;d++)if("undefined"!=typeof b.items[d]){for(var e={},f=0;f<a.length;f++){var g=a[f],h="."+g+"_"+d,i=b.elem.find(h).val();e[g]="undefined"==typeof i?!1:i}c.push(e)}return b.items=c,b.callbacks.save(b,c),b},b.getBaseObjectKeys=function(){for(var a=[],c=b.items.length>0?b.items:[b._baseObj],d=0;d<c.length;d++)if("undefined"!=typeof c[d]){for(var e in c[d])c[d].hasOwnProperty(e)&&a.push(e);break}return a},b.getBaseObject=function(){for(var a={},c=b.getBaseObjectKeys(),d=0;d<c.length;d++)a[c[d]]="";return a},b.getNamespacedEvents=function(a){for(var a=a.split(" "),b=[],c=0;c<a.length;c++)b.push(a[c]+".repeater");return b.join(" ")},b.isElement=function(a){try{return a instanceof HTMLElement}catch(b){return"object"==typeof a&&1===a.nodeType&&"object"==typeof a.style&&"object"==typeof a.ownerDocument}},b.init()};