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);
48 var editRow, rowData, val,
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 $(t.what+id).hide().after(editRow).after('<tr class="hidden"></tr>');
61 val = $('.name', rowData);
62 val.find( 'img' ).replaceWith( function() { return this.alt; } );
64 $(':input[name="name"]', editRow).val( val );
66 val = $('.slug', rowData);
67 val.find( 'img' ).replaceWith( function() { return this.alt; } );
69 $(':input[name="slug"]', editRow).val( val );
71 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
72 $('.ptitle', editRow).eq(0).focus();
78 var params, fields, tax = $('input[name="taxonomy"]').val() || '';
80 if( typeof(id) === 'object' ) {
84 $( 'table.widefat .spinner' ).addClass( 'is-active' );
87 action: 'inline-save-tax',
93 fields = $('#edit-'+id).find(':input').serialize();
94 params = fields + '&' + $.param(params);
97 $.post( ajaxurl, params,
99 var row, new_id, option_value;
100 $( 'table.widefat .spinner' ).removeClass( 'is-active' );
103 if ( -1 !== r.indexOf( '<tr' ) ) {
104 $(inlineEditTax.what+id).siblings('tr.hidden').addBack().remove();
105 new_id = $(r).attr('id');
107 $('#edit-'+id).before(r).remove();
110 option_value = new_id.replace( inlineEditTax.type + '-', '' );
111 row = $( '#' + new_id );
114 row = $( inlineEditTax.what + id );
117 // Update the value in the Parent dropdown.
118 $( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
122 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
125 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
132 revert : function() {
133 var id = $('table.widefat tr.inline-editor').attr('id');
136 $( 'table.widefat .spinner' ).removeClass( 'is-active' );
137 $('#'+id).siblings('tr.hidden').addBack().remove();
138 id = id.substr( id.lastIndexOf('-') + 1 );
139 $(this.what+id).show();
145 getId : function(o) {
146 var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
147 return parts[parts.length - 1];
151 $(document).ready(function(){inlineEditTax.init();});