1 line
2.7 KiB
JavaScript
1 line
2.7 KiB
JavaScript
(function(a){inlineEditTax={init:function(){var b=this,c=a("#inline-edit");b.type=a("#the-list").attr("className").substr(5);b.what="#"+b.type+"-";b.rows=a("tr.iedit");c.keyup(function(d){if(d.which==27){return inlineEditTax.revert()}});a("a.cancel",c).click(function(){return inlineEditTax.revert()});a("a.save",c).click(function(){return inlineEditTax.save(this)});a("input, select",c).keydown(function(d){if(d.which==13){return inlineEditTax.save(this)}});b.addEvents(b.rows);a('#posts-filter input[type="submit"]').click(function(d){if(a("form#posts-filter tr.inline-editor").length>0){b.revert()}})},toggle:function(c){var b=this;a(b.what+b.getId(c)).css("display")=="none"?b.revert():b.edit(c)},addEvents:function(b){b.each(function(){a(this).find("a.editinline").click(function(){inlineEditTax.edit(this);return false})})},edit:function(b){var i=this,d,e,f;i.revert();if(typeof(b)=="object"){b=i.getId(b)}d=a("#inline-edit").clone(true),rowData=a("#inline_"+b);a("td",d).attr("colspan",a(".widefat:first thead th:visible").length);if(a(i.what+b).hasClass("alternate")){a(d).addClass("alternate")}a(i.what+b).hide().after(d);a(':input[name="name"]',d).val(a(".name",rowData).text());a(':input[name="slug"]',d).val(a(".slug",rowData).text());e=a(".cat_parent",rowData).text();if(e!="0"){a('select[name="parent"]',d).val(e)}f=a('select[name="parent"] option[value="'+b+'"]',d);if(f.length>0){var h=f[0].className.split("-")[1],g,c=true,j;while(c){g=g.next("option");if(g.length==0){break}j=g[0].className.split("-")[1];if(j<=h){c=false}else{g.remove();g=f}}f.remove()}a(d).attr("id","edit-"+b).addClass("inline-editor").show();a(".ptitle",d).eq(0).focus();return false},save:function(d){var c,b;if(typeof(d)=="object"){d=this.getId(d)}a("table.widefat .inline-edit-save .waiting").show();c={action:"inline-save-tax",tax_type:this.type,tax_ID:d};b=a("#edit-"+d+" :input").fieldSerialize();c=b+"&"+a.param(c);a.post("admin-ajax.php",c,function(e){a("table.widefat .inline-edit-save .waiting").hide();if(e){if(-1!=e.indexOf("<tr")){a(inlineEditTax.what+d).remove();a("#edit-"+d).before(e).remove();var f=a(inlineEditTax.what+d);f.hide();inlineEditTax.addEvents(f);f.fadeIn()}else{a("#edit-"+d+" .inline-edit-save .error").html(e).show()}}else{a("#edit-"+d+" .inline-edit-save .error").html(inlineEditL10n.error).show()}});return false},revert:function(){var b=a("table.widefat tr.inline-editor").attr("id");if(b){a("table.widefat .inline-edit-save .waiting").hide();a("#"+b).remove();b=b.substr(b.lastIndexOf("-")+1);a(this.what+b).show()}return false},getId:function(c){var d=c.tagName=="TR"?c.id:a(c).parents("tr").attr("id"),b=d.split("-");return b[b.length-1]}};a(document).ready(function(){inlineEditTax.init()})})(jQuery); |