|
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 $('#the-list').on('click', 'a.editinline', 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 if ($(row).prev('tr').hasClass('alternate')) |
|
95 $(row).removeClass('alternate'); |
|
96 } |
|
97 ); |
|
98 return false; |
|
99 }, |
|
100 |
|
101 revert : function() { |
|
102 var id = $('table.widefat tr.inline-editor').attr('id'); |
|
103 |
|
104 if ( id ) { |
|
105 $('table.widefat .spinner').hide(); |
|
106 $('#'+id).remove(); |
|
107 id = id.substr( id.lastIndexOf('-') + 1 ); |
|
108 $(this.what+id).show(); |
|
109 } |
|
110 |
|
111 return false; |
|
112 }, |
|
113 |
|
114 getId : function(o) { |
|
115 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); |
|
116 return parts[parts.length - 1]; |
|
117 } |
|
118 }; |
|
119 |
|
120 $(document).ready(function(){inlineEditTax.init();}); |
|
121 })(jQuery); |