jQuery(document).ready(function($){$(document.body).on("click",".aat-hide-show-tabs",function(e){e.preventDefault();var tabs=$(".aat-repeatable-row-standard-fields"),el=$(this);el.text()==el.data("text-swap")?el.text(el.data("text-original")):el.text(el.data("text-swap")),el.text()===el.data("text-swap")?tabs.show():el.text()===el.data("text-original")&&tabs.hide()});var AAT_Configuration={init:function(){this.add(),this.edit(),this.move(),this.remove()},clone_repeatable:function(row){var key=highest=1;return row.parent().find(".aat_repeatable_row").each(function(){var current=$(this).data("key");parseInt(current)>highest&&(highest=current)}),key=highest+=1,clone=row.clone(),clone.find("select").each(function(){$(this).val(row.find('select[name="'+$(this).attr("name")+'"]').val())}),clone.attr("data-key",key),clone.find("input, select").val("").each(function(){var name=$(this).attr("name"),id=$(this).attr("id");name&&(name=name.replace(/\[(\d+)\]/,"["+parseInt(key)+"]"),$(this).attr("name",name)),$(this).attr("data-key",key),void 0!==id&&(id=id.replace(/(\d+)/,parseInt(key)),$(this).attr("id",id))}),clone.find("label").val("").each(function(){var labelFor=$(this).attr("for");void 0!==labelFor&&(labelFor=labelFor.replace(/(\d+)/,parseInt(key)),$(this).attr("for",labelFor))}),clone.find(".affiliate-area-tabs-title").each(function(){$(this).html("New Custom Tab")}),clone.find(".aat-tab-default").remove(),clone.find(".aat-tab-number-key").each(function(){$(this).text(parseInt(key))}),clone.find(".affiliate-area-hide-tabs").each(function(){$(this).val("yes").removeAttr("checked")}),clone.find(".aat-tab-title, .aat-tab-content").show(),clone},add:function(){$(document.body).on("click",".aat-add-repeatable",function(e){e.preventDefault();var row=$(this).parent().prev(".aat_repeatable_row"),clone=AAT_Configuration.clone_repeatable(row);clone.insertAfter(row),clone.find(".aat-repeatable-row-standard-fields").show(),clone.find("input, select").filter(":visible").eq(0).focus()})},edit:function(){$(document.body).on("click",".aat-repeatable-row-title",function(e){e.preventDefault(),$(this).next(".aat-repeatable-row-standard-fields").toggle(),$(this).find(".affiliate-area-tabs-edit .dashicons").toggleClass("dashicons-arrow-down dashicons-arrow-up")})},move:function(){$(".aat_repeatable_table .aat-repeatables-wrap").sortable({handle:".aat-draghandle-anchor",items:".aat_repeatable_row",opacity:.6,cursor:"move",axis:"y",update:function(){var key=1;$(this).find(".aat_repeatable_row").each(function(){$(this).attr("data-key",key),$(this).find(".aat-tab-number-key").text(parseInt(key)),$(this).find("input, select").each(function(){var name=$(this).attr("name"),id=$(this).attr("id");name&&(name=name.replace(/\[(\d+)\]/,"["+parseInt(key)+"]"),$(this).attr("name",name)),$(this).attr("data-key",key),void 0!==id&&(id=id.replace(/(\d+)/,parseInt(key)),$(this).attr("id",id))}),$(this).find("label").val("").each(function(){var labelFor=$(this).attr("for");void 0!==labelFor&&(labelFor=labelFor.replace(/(\d+)/,parseInt(key)),$(this).attr("for",labelFor))}),key++})}})},remove:function(){$(document.body).on("click",".aat_remove_repeatable",function(e){if(e.preventDefault(),confirm("Are you sure you want to delete this tab?")){var firstFocusable,row=$(this).parents(".aat_repeatable_row");row.parent().find(".aat_repeatable_row").length;firstFocusable=($(this).is(".ui-sortable .aat_repeatable_row:first-child .aat_remove_repeatable")?row.next(".aat_repeatable_row"):row.prev(".aat_repeatable_row")).find("select, input, textarea, button").filter(":visible").eq(0),$("input, select",row).val(""),row.remove(),firstFocusable.focus();var key=1;$(".aat-repeatables-wrap").find(".aat_repeatable_row").each(function(){$(this).attr("data-key",key),$(this).find(".aat-tab-number-key").text(parseInt(key)),$(this).find("input, select").each(function(){var name=$(this).attr("name"),id=$(this).attr("id");name&&(name=name.replace(/\[(\d+)\]/,"["+parseInt(key)+"]"),$(this).attr("name",name)),$(this).attr("data-key",key),void 0!==id&&(id=id.replace(/(\d+)/,parseInt(key)),$(this).attr("id",id))}),$(this).find("label").val("").each(function(){var labelFor=$(this).attr("for");void 0!==labelFor&&(labelFor=labelFor.replace(/(\d+)/,parseInt(key)),$(this).attr("for",labelFor))}),key++})}})}};AAT_Configuration.init()});