WordPress/wp-admin/js/inline-edit-tax.min.js

1 line
2.5 KiB
JavaScript

var inlineEditTax;!function(a){inlineEditTax={init:function(){var t=this,i=a("#inline-edit");t.type=a("#the-list").attr("data-wp-lists").substr(5),t.what="#"+t.type+"-",a("#the-list").on("click","a.editinline",function(){return inlineEditTax.edit(this),!1}),i.keyup(function(t){if(27===t.which)return inlineEditTax.revert()}),a("a.cancel",i).click(function(){return inlineEditTax.revert()}),a("a.save",i).click(function(){return inlineEditTax.save(this)}),a("input, select",i).keydown(function(t){if(13===t.which)return inlineEditTax.save(this)}),a('#posts-filter input[type="submit"]').mousedown(function(){t.revert()})},toggle:function(t){var i=this;"none"===a(i.what+i.getId(t)).css("display")?i.revert():i.edit(t)},edit:function(t){var i,e,n=this;return n.revert(),"object"==typeof t&&(t=n.getId(t)),i=a("#inline-edit").clone(!0),e=a("#inline_"+t),a("td",i).attr("colspan",a(".widefat:first thead th:visible").length),a(n.what+t).hide().after(i).after('<tr class="hidden"></tr>'),(n=a(".name",e)).find("img").replaceWith(function(){return this.alt}),n=n.text(),a(':input[name="name"]',i).val(n),(n=a(".slug",e)).find("img").replaceWith(function(){return this.alt}),n=n.text(),a(':input[name="slug"]',i).val(n),a(i).attr("id","edit-"+t).addClass("inline-editor").show(),a(".ptitle",i).eq(0).focus(),!1},save:function(n){var t=a('input[name="taxonomy"]').val()||"";return"object"==typeof n&&(n=this.getId(n)),a("table.widefat .spinner").addClass("is-active"),t={action:"inline-save-tax",tax_type:this.type,tax_ID:n,taxonomy:t},t=a("#edit-"+n).find(":input").serialize()+"&"+a.param(t),a.post(ajaxurl,t,function(t){var i,e;a("table.widefat .spinner").removeClass("is-active"),t?-1!==t.indexOf("<tr")?(a(inlineEditTax.what+n).siblings("tr.hidden").addBack().remove(),i=a(t).attr("id"),a("#edit-"+n).before(t).remove(),i=i?(e=i.replace(inlineEditTax.type+"-",""),a("#"+i)):(e=n,a(inlineEditTax.what+n)),a("#parent").find("option[value="+e+"]").text(i.find(".row-title").text()),i.hide().fadeIn()):a("#edit-"+n+" .inline-edit-save .error").html(t).show():a("#edit-"+n+" .inline-edit-save .error").html(inlineEditL10n.error).show()}),!1},revert:function(){var t=a("table.widefat tr.inline-editor").attr("id");return t&&(a("table.widefat .spinner").removeClass("is-active"),a("#"+t).siblings("tr.hidden").addBack().remove(),t=t.substr(t.lastIndexOf("-")+1),a(this.what+t).show()),!1},getId:function(t){t=("TR"===t.tagName?t.id:a(t).parents("tr").attr("id")).split("-");return t[t.length-1]}},a(document).ready(function(){inlineEditTax.init()})}(jQuery);