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