1 (function(a){inlineEditTax={init:function(){var b=this,c=a("#inline-edit");b.type=a("#the-list").attr("class").substr(5);b.what="#"+b.type+"-";a(".editinline").live("click",function(){inlineEditTax.edit(this);return false});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)}});a('#posts-filter input[type="submit"]').mousedown(function(d){b.revert()})},toggle:function(c){var b=this;a(b.what+b.getId(c)).css("display")=="none"?b.revert():b.edit(c)},edit:function(d){var c=this,b;c.revert();if(typeof(d)=="object"){d=c.getId(d)}b=a("#inline-edit").clone(true),rowData=a("#inline_"+d);a("td",b).attr("colspan",a(".widefat:first thead th:visible").length);if(a(c.what+d).hasClass("alternate")){a(b).addClass("alternate")}a(c.what+d).hide().after(b);a(':input[name="name"]',b).val(a(".name",rowData).text());a(':input[name="slug"]',b).val(a(".slug",rowData).text());a(b).attr("id","edit-"+d).addClass("inline-editor").show();a(".ptitle",b).eq(0).focus();return false},save:function(e){var d,b,c=a('input[name="taxonomy"]').val()||"";if(typeof(e)=="object"){e=this.getId(e)}a("table.widefat .inline-edit-save .waiting").show();d={action:"inline-save-tax",tax_type:this.type,tax_ID:e,taxonomy:c};b=a("#edit-"+e+" :input").serialize();d=b+"&"+a.param(d);a.post(ajaxurl,d,function(g){var h,f;a("table.widefat .inline-edit-save .waiting").hide();if(g){if(-1!=g.indexOf("<tr")){a(inlineEditTax.what+e).remove();f=a(g).attr("id");a("#edit-"+e).before(g).remove();h=f?a("#"+f):a(inlineEditTax.what+e);h.hide().fadeIn()}else{a("#edit-"+e+" .inline-edit-save .error").html(g).show()}}else{a("#edit-"+e+" .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); |
1 |
|
2 (function($) { |
|
3 inlineEditTax = { |
|
4 |
|
5 init : function() { |
|
6 var t = this, row = $('#inline-edit'); |
|
7 |
|
8 t.type = $('#the-list').attr('data-wp-lists').substr(5); |
|
9 t.what = '#'+t.type+'-'; |
|
10 |
|
11 $('.editinline').live('click', function(){ |
|
12 inlineEditTax.edit(this); |
|
13 return false; |
|
14 }); |
|
15 |
|
16 // prepare the edit row |
|
17 row.keyup(function(e) { if(e.which == 27) return inlineEditTax.revert(); }); |
|
18 |
|
19 $('a.cancel', row).click(function() { return inlineEditTax.revert(); }); |
|
20 $('a.save', row).click(function() { return inlineEditTax.save(this); }); |
|
21 $('input, select', row).keydown(function(e) { if(e.which == 13) return inlineEditTax.save(this); }); |
|
22 |
|
23 $('#posts-filter input[type="submit"]').mousedown(function(e){ |
|
24 t.revert(); |
|
25 }); |
|
26 }, |
|
27 |
|
28 toggle : function(el) { |
|
29 var t = this; |
|
30 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); |
|
31 }, |
|
32 |
|
33 edit : function(id) { |
|
34 var t = this, editRow; |
|
35 t.revert(); |
|
36 |
|
37 if ( typeof(id) == 'object' ) |
|
38 id = t.getId(id); |
|
39 |
|
40 editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id); |
|
41 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length); |
|
42 |
|
43 if ( $(t.what+id).hasClass('alternate') ) |
|
44 $(editRow).addClass('alternate'); |
|
45 |
|
46 $(t.what+id).hide().after(editRow); |
|
47 |
|
48 $(':input[name="name"]', editRow).val( $('.name', rowData).text() ); |
|
49 $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() ); |
|
50 |
|
51 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
|
52 $('.ptitle', editRow).eq(0).focus(); |
|
53 |
|
54 return false; |
|
55 }, |
|
56 |
|
57 save : function(id) { |
|
58 var params, fields, tax = $('input[name="taxonomy"]').val() || ''; |
|
59 |
|
60 if( typeof(id) == 'object' ) |
|
61 id = this.getId(id); |
|
62 |
|
63 $('table.widefat .spinner').show(); |
|
64 |
|
65 params = { |
|
66 action: 'inline-save-tax', |
|
67 tax_type: this.type, |
|
68 tax_ID: id, |
|
69 taxonomy: tax |
|
70 }; |
|
71 |
|
72 fields = $('#edit-'+id+' :input').serialize(); |
|
73 params = fields + '&' + $.param(params); |
|
74 |
|
75 // make ajax request |
|
76 $.post( ajaxurl, params, |
|
77 function(r) { |
|
78 var row, new_id; |
|
79 $('table.widefat .spinner').hide(); |
|
80 |
|
81 if (r) { |
|
82 if ( -1 != r.indexOf('<tr') ) { |
|
83 $(inlineEditTax.what+id).remove(); |
|
84 new_id = $(r).attr('id'); |
|
85 |
|
86 $('#edit-'+id).before(r).remove(); |
|
87 row = new_id ? $('#'+new_id) : $(inlineEditTax.what+id); |
|
88 row.hide().fadeIn(); |
|
89 } else |
|
90 $('#edit-'+id+' .inline-edit-save .error').html(r).show(); |
|
91 } else |
|
92 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show(); |
|
93 } |
|
94 ); |
|
95 return false; |
|
96 }, |
|
97 |
|
98 revert : function() { |
|
99 var id = $('table.widefat tr.inline-editor').attr('id'); |
|
100 |
|
101 if ( id ) { |
|
102 $('table.widefat .spinner').hide(); |
|
103 $('#'+id).remove(); |
|
104 id = id.substr( id.lastIndexOf('-') + 1 ); |
|
105 $(this.what+id).show(); |
|
106 } |
|
107 |
|
108 return false; |
|
109 }, |
|
110 |
|
111 getId : function(o) { |
|
112 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); |
|
113 return parts[parts.length - 1]; |
|
114 } |
|
115 }; |
|
116 |
|
117 $(document).ready(function(){inlineEditTax.init();}); |
|
118 })(jQuery); |