1 /* global inlineEditL10n, ajaxurl */
2 window.wp = window.wp || {};
9 var t = this, row = $('#inline-edit');
11 t.type = $('#the-list').attr('data-wp-lists').substr(5);
12 t.what = '#'+t.type+'-';
14 $('#the-list').on('click', 'a.editinline', function(){
15 inlineEditTax.edit(this);
19 // prepare the edit row
20 row.keyup( function( e ) {
21 if ( e.which === 27 ) {
22 return inlineEditTax.revert();
26 $( '.cancel', row ).click( function() {
27 return inlineEditTax.revert();
29 $( '.save', row ).click( function() {
30 return inlineEditTax.save(this);
32 $( 'input, select', row ).keydown( function( e ) {
33 if ( e.which === 13 ) {
34 return inlineEditTax.save( this );
38 $( '#posts-filter input[type="submit"]' ).mousedown( function() {
43 toggle : function(el) {
45 $(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el);
49 var editRow, rowData, val,
53 if ( typeof(id) === 'object' ) {
57 editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
58 $( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length );
60 $(t.what+id).hide().after(editRow).after('<tr class="hidden"></tr>');
62 val = $('.name', rowData);
63 val.find( 'img' ).replaceWith( function() { return this.alt; } );
65 $(':input[name="name"]', editRow).val( val );
67 val = $('.slug', rowData);
68 val.find( 'img' ).replaceWith( function() { return this.alt; } );
70 $(':input[name="slug"]', editRow).val( val );
72 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
73 $('.ptitle', editRow).eq(0).focus();
79 var params, fields, tax = $('input[name="taxonomy"]').val() || '';
81 if( typeof(id) === 'object' ) {
85 $( 'table.widefat .spinner' ).addClass( 'is-active' );
88 action: 'inline-save-tax',
94 fields = $('#edit-'+id).find(':input').serialize();
95 params = fields + '&' + $.param(params);
98 $.post( ajaxurl, params,
100 var row, new_id, option_value,
101 $errorSpan = $( '#edit-' + id + ' .inline-edit-save .error' );
103 $( 'table.widefat .spinner' ).removeClass( 'is-active' );
106 if ( -1 !== r.indexOf( '<tr' ) ) {
107 $(inlineEditTax.what+id).siblings('tr.hidden').addBack().remove();
108 new_id = $(r).attr('id');
110 $('#edit-'+id).before(r).remove();
113 option_value = new_id.replace( inlineEditTax.type + '-', '' );
114 row = $( '#' + new_id );
117 row = $( inlineEditTax.what + id );
120 // Update the value in the Parent dropdown.
121 $( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
123 row.hide().fadeIn( 400, function() {
124 // Move focus back to the taxonomy title.
125 row.find( '.row-title' ).focus();
126 wp.a11y.speak( inlineEditL10n.saved );
130 $errorSpan.html( r ).show();
131 // Some error strings may contain HTML entities (e.g. `“`), let's use the HTML element's text.
132 wp.a11y.speak( $errorSpan.text() );
135 $errorSpan.html( inlineEditL10n.error ).show();
136 wp.a11y.speak( inlineEditL10n.error );
142 revert : function() {
143 var id = $('table.widefat tr.inline-editor').attr('id');
146 $( 'table.widefat .spinner' ).removeClass( 'is-active' );
147 $('#'+id).siblings('tr.hidden').addBack().remove();
148 id = id.substr( id.lastIndexOf('-') + 1 );
149 // Show the taxonomy listing and move focus back to the taxonomy title.
150 $( this.what + id ).show().find( '.row-title' ).focus();
154 getId : function(o) {
155 var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
156 return parts[parts.length - 1];
160 $(document).ready(function(){inlineEditTax.init();});
161 })( jQuery, window.wp );