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