!function(t){"function"==typeof define&&define.amd?define("customTaxonomies",t):t()}(function(){"use strict";function t(){this.addButton=i("#c27-add-taxonomy"),this.container=i("#c27-custom-taxonomies"),void 0===c27_custom_taxonomies.taxonomies&&(c27_custom_taxonomies.taxonomies=[]),this.addTaxonomy(c27_custom_taxonomies.taxonomies),this.bindEvents(),i("#settings-taxonomies .taxonomy-fields").sortable()}var i;i=jQuery,t.prototype={Window:i(window),form:[],bindEvents:function(){this.addButton.on("click",i.proxy(this.onButtonClick,this)),this.container.on("click","[data-delete-btn]",i.proxy(this.deleteTaxonomy,this)),this.container.on("click","[data-edit-btn]",i.proxy(this.editTaxonomy,this)),this.container.on("keyup","input[data-field-label]",i.proxy(this.updateLabel,this))},onButtonClick:function(t){t.preventDefault(),this.addTaxonomy()},onSubmit:function(t){var n=this.container.find(":input"),e=!1;n.removeClass("required-field");for(var o=0;o<=n.length;++o){var a=i(n[o]);i(a).val()||(a.addClass("required-field"),e=!0)}e&&(t.preventDefault(),alert(c27_custom_taxonomies.requiredMsg))},addTaxonomy:function(t){t=t||[{slug:"",label:"",can_edit_slug:!0}],t=wp.template("c27-custom-taxonomies")({taxonomies:t,count:this.container.children().length}),this.container.append(t)},deleteTaxonomy:function(t){t.preventDefault(),t.stopPropagation();var t=i(t.currentTarget);confirm(c27_custom_taxonomies.deleteMsg)&&(t.parents("div[data-taxonomy]:first").remove(),(t=this.container.children("div[data-taxonomy]")).length||this.addTaxonomy(),t.each(function(e){i(this).find(":input").each(function(){var t=i(this),n=t.attr("name");t.attr("name",n.replace(/job_manager_custom_taxonomy\[(\d+)\]/,"job_manager_custom_taxonomy["+e+"]"))})}))},editTaxonomy:function(t){t.preventDefault();t=i(t.currentTarget);t.parents(".row-item").hasClass("open")?this.container.find(".row-item").removeClass("open"):(this.container.find(".row-item").removeClass("open"),t.parents(".row-item").addClass("open"))},updateLabel:function(t){var t=i(t.currentTarget),n=t.parents(".head-button:first"),e=n.find("[data-label]"),o=n.find("[data-slug]"),n=n.find("input[data-field-slug]"),t=t.val();n.prop("readonly")||n.val(this._toSlug(t)),e.text(t||"(click to edit)"),o.text(n.val())},_toSlug:function(t){return(t=i.trim(t.toLowerCase().replace(/([^a-z0-9])/gi," ",t))).replace(/\s+/g,"-",t)}},i(document).ready(function(){new t})});
