1 /* global inlineEditL10n, ajaxurl */
8 var t = this, row = $('#inline-edit');
10 t.type = $('#the-list').attr('data-wp-lists').substr(5);
11 t.what = '#'+t.type+'-';
13 $('#the-list').on('click', 'a.editinline', function(){
14 inlineEditTax.edit(this);
18 // prepare the edit row
19 row.keyup( function( e ) {
20 if ( e.which === 27 ) {
21 return inlineEditTax.revert();
25 $( 'a.cancel', row ).click( function() {
26 return inlineEditTax.revert();
28 $( 'a.save', row ).click( function() {
29 return inlineEditTax.save(this);
31 $( 'input, select', row ).keydown( function( e ) {
32 if ( e.which === 13 ) {
33 return inlineEditTax.save( this );
37 $( '#posts-filter input[type="submit"]' ).mousedown( function() {
42 toggle : function(el) {
44 $(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el);
52 if ( typeof(id) === 'object' ) {
56 editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
57 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
59 if ( $( t.what + id ).hasClass( 'alternate' ) ) {
60 $(editRow).addClass('alternate');
63 $(t.what+id).hide().after(editRow);
65 $(':input[name="name"]', editRow).val( $('.name', rowData).text() );
66 $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() );
68 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
69 $('.ptitle', editRow).eq(0).focus();
75 var params, fields, tax = $('input[name="taxonomy"]').val() || '';
77 if( typeof(id) === 'object' ) {
81 $('table.widefat .spinner').show();
84 action: 'inline-save-tax',
90 fields = $('#edit-'+id).find(':input').serialize();
91 params = fields + '&' + $.param(params);
94 $.post( ajaxurl, params,
97 $('table.widefat .spinner').hide();
100 if ( -1 !== r.indexOf( '<tr' ) ) {
101 $(inlineEditTax.what+id).remove();
102 new_id = $(r).attr('id');
104 $('#edit-'+id).before(r).remove();
105 row = new_id ? $('#'+new_id) : $(inlineEditTax.what+id);
108 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
111 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
114 if ( $( row ).prev( 'tr' ).hasClass( 'alternate' ) ) {
115 $(row).removeClass('alternate');
122 revert : function() {
123 var id = $('table.widefat tr.inline-editor').attr('id');
126 $('table.widefat .spinner').hide();
128 id = id.substr( id.lastIndexOf('-') + 1 );
129 $(this.what+id).show();
135 getId : function(o) {
136 var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
137 return parts[parts.length - 1];
141 $(document).ready(function(){inlineEditTax.init();});