Edit File by line
/home/barbar84/www/wp-admin/js
File: inline-edit-tax.js
/**
[0] Fix | Delete
* This file is used on the term overview page to power quick-editing terms.
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-admin/js/inline-edit-tax.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
/* global ajaxurl, inlineEditTax */
[6] Fix | Delete
[7] Fix | Delete
window.wp = window.wp || {};
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Consists of functions relevant to the inline taxonomy editor.
[11] Fix | Delete
*
[12] Fix | Delete
* @namespace inlineEditTax
[13] Fix | Delete
*
[14] Fix | Delete
* @property {string} type The type of inline edit we are currently on.
[15] Fix | Delete
* @property {string} what The type property with a hash prefixed and a dash
[16] Fix | Delete
* suffixed.
[17] Fix | Delete
*/
[18] Fix | Delete
( function( $, wp ) {
[19] Fix | Delete
[20] Fix | Delete
window.inlineEditTax = {
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Initializes the inline taxonomy editor by adding event handlers to be able to
[24] Fix | Delete
* quick edit.
[25] Fix | Delete
*
[26] Fix | Delete
* @since 2.7.0
[27] Fix | Delete
*
[28] Fix | Delete
* @this inlineEditTax
[29] Fix | Delete
* @memberof inlineEditTax
[30] Fix | Delete
* @return {void}
[31] Fix | Delete
*/
[32] Fix | Delete
init : function() {
[33] Fix | Delete
var t = this, row = $('#inline-edit');
[34] Fix | Delete
[35] Fix | Delete
t.type = $('#the-list').attr('data-wp-lists').substr(5);
[36] Fix | Delete
t.what = '#'+t.type+'-';
[37] Fix | Delete
[38] Fix | Delete
$( '#the-list' ).on( 'click', '.editinline', function() {
[39] Fix | Delete
$( this ).attr( 'aria-expanded', 'true' );
[40] Fix | Delete
inlineEditTax.edit( this );
[41] Fix | Delete
});
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Cancels inline editing when pressing Escape inside the inline editor.
[45] Fix | Delete
*
[46] Fix | Delete
* @param {Object} e The keyup event that has been triggered.
[47] Fix | Delete
*/
[48] Fix | Delete
row.on( 'keyup', function( e ) {
[49] Fix | Delete
// 27 = [Escape].
[50] Fix | Delete
if ( e.which === 27 ) {
[51] Fix | Delete
return inlineEditTax.revert();
[52] Fix | Delete
}
[53] Fix | Delete
});
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Cancels inline editing when clicking the cancel button.
[57] Fix | Delete
*/
[58] Fix | Delete
$( '.cancel', row ).on( 'click', function() {
[59] Fix | Delete
return inlineEditTax.revert();
[60] Fix | Delete
});
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Saves the inline edits when clicking the save button.
[64] Fix | Delete
*/
[65] Fix | Delete
$( '.save', row ).on( 'click', function() {
[66] Fix | Delete
return inlineEditTax.save(this);
[67] Fix | Delete
});
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Saves the inline edits when pressing Enter inside the inline editor.
[71] Fix | Delete
*/
[72] Fix | Delete
$( 'input, select', row ).on( 'keydown', function( e ) {
[73] Fix | Delete
// 13 = [Enter].
[74] Fix | Delete
if ( e.which === 13 ) {
[75] Fix | Delete
return inlineEditTax.save( this );
[76] Fix | Delete
}
[77] Fix | Delete
});
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Saves the inline edits on submitting the inline edit form.
[81] Fix | Delete
*/
[82] Fix | Delete
$( '#posts-filter input[type="submit"]' ).on( 'mousedown', function() {
[83] Fix | Delete
t.revert();
[84] Fix | Delete
});
[85] Fix | Delete
},
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Toggles the quick edit based on if it is currently shown or hidden.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 2.7.0
[91] Fix | Delete
*
[92] Fix | Delete
* @this inlineEditTax
[93] Fix | Delete
* @memberof inlineEditTax
[94] Fix | Delete
*
[95] Fix | Delete
* @param {HTMLElement} el An element within the table row or the table row
[96] Fix | Delete
* itself that we want to quick edit.
[97] Fix | Delete
* @return {void}
[98] Fix | Delete
*/
[99] Fix | Delete
toggle : function(el) {
[100] Fix | Delete
var t = this;
[101] Fix | Delete
[102] Fix | Delete
$(t.what+t.getId(el)).css('display') === 'none' ? t.revert() : t.edit(el);
[103] Fix | Delete
},
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Shows the quick editor
[107] Fix | Delete
*
[108] Fix | Delete
* @since 2.7.0
[109] Fix | Delete
*
[110] Fix | Delete
* @this inlineEditTax
[111] Fix | Delete
* @memberof inlineEditTax
[112] Fix | Delete
*
[113] Fix | Delete
* @param {string|HTMLElement} id The ID of the term we want to quick edit or an
[114] Fix | Delete
* element within the table row or the
[115] Fix | Delete
* table row itself.
[116] Fix | Delete
* @return {boolean} Always returns false.
[117] Fix | Delete
*/
[118] Fix | Delete
edit : function(id) {
[119] Fix | Delete
var editRow, rowData, val,
[120] Fix | Delete
t = this;
[121] Fix | Delete
t.revert();
[122] Fix | Delete
[123] Fix | Delete
// Makes sure we can pass an HTMLElement as the ID.
[124] Fix | Delete
if ( typeof(id) === 'object' ) {
[125] Fix | Delete
id = t.getId(id);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
[129] Fix | Delete
$( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.wp-list-table.widefat:first thead' ).length );
[130] Fix | Delete
[131] Fix | Delete
$(t.what+id).hide().after(editRow).after('<tr class="hidden"></tr>');
[132] Fix | Delete
[133] Fix | Delete
val = $('.name', rowData);
[134] Fix | Delete
val.find( 'img' ).replaceWith( function() { return this.alt; } );
[135] Fix | Delete
val = val.text();
[136] Fix | Delete
$(':input[name="name"]', editRow).val( val );
[137] Fix | Delete
[138] Fix | Delete
val = $('.slug', rowData);
[139] Fix | Delete
val.find( 'img' ).replaceWith( function() { return this.alt; } );
[140] Fix | Delete
val = val.text();
[141] Fix | Delete
$(':input[name="slug"]', editRow).val( val );
[142] Fix | Delete
[143] Fix | Delete
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
[144] Fix | Delete
$('.ptitle', editRow).eq(0).trigger( 'focus' );
[145] Fix | Delete
[146] Fix | Delete
return false;
[147] Fix | Delete
},
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Saves the quick edit data.
[151] Fix | Delete
*
[152] Fix | Delete
* Saves the quick edit data to the server and replaces the table row with the
[153] Fix | Delete
* HTML retrieved from the server.
[154] Fix | Delete
*
[155] Fix | Delete
* @since 2.7.0
[156] Fix | Delete
*
[157] Fix | Delete
* @this inlineEditTax
[158] Fix | Delete
* @memberof inlineEditTax
[159] Fix | Delete
*
[160] Fix | Delete
* @param {string|HTMLElement} id The ID of the term we want to quick edit or an
[161] Fix | Delete
* element within the table row or the
[162] Fix | Delete
* table row itself.
[163] Fix | Delete
* @return {boolean} Always returns false.
[164] Fix | Delete
*/
[165] Fix | Delete
save : function(id) {
[166] Fix | Delete
var params, fields, tax = $('input[name="taxonomy"]').val() || '';
[167] Fix | Delete
[168] Fix | Delete
// Makes sure we can pass an HTMLElement as the ID.
[169] Fix | Delete
if( typeof(id) === 'object' ) {
[170] Fix | Delete
id = this.getId(id);
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$( 'table.widefat .spinner' ).addClass( 'is-active' );
[174] Fix | Delete
[175] Fix | Delete
params = {
[176] Fix | Delete
action: 'inline-save-tax',
[177] Fix | Delete
tax_type: this.type,
[178] Fix | Delete
tax_ID: id,
[179] Fix | Delete
taxonomy: tax
[180] Fix | Delete
};
[181] Fix | Delete
[182] Fix | Delete
fields = $('#edit-'+id).find(':input').serialize();
[183] Fix | Delete
params = fields + '&' + $.param(params);
[184] Fix | Delete
[185] Fix | Delete
// Do the Ajax request to save the data to the server.
[186] Fix | Delete
$.post( ajaxurl, params,
[187] Fix | Delete
/**
[188] Fix | Delete
* Handles the response from the server
[189] Fix | Delete
*
[190] Fix | Delete
* Handles the response from the server, replaces the table row with the response
[191] Fix | Delete
* from the server.
[192] Fix | Delete
*
[193] Fix | Delete
* @param {string} r The string with which to replace the table row.
[194] Fix | Delete
*/
[195] Fix | Delete
function(r) {
[196] Fix | Delete
var row, new_id, option_value,
[197] Fix | Delete
$errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ),
[198] Fix | Delete
$error = $errorNotice.find( '.error' );
[199] Fix | Delete
[200] Fix | Delete
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
[201] Fix | Delete
[202] Fix | Delete
if (r) {
[203] Fix | Delete
if ( -1 !== r.indexOf( '<tr' ) ) {
[204] Fix | Delete
$(inlineEditTax.what+id).siblings('tr.hidden').addBack().remove();
[205] Fix | Delete
new_id = $(r).attr('id');
[206] Fix | Delete
[207] Fix | Delete
$('#edit-'+id).before(r).remove();
[208] Fix | Delete
[209] Fix | Delete
if ( new_id ) {
[210] Fix | Delete
option_value = new_id.replace( inlineEditTax.type + '-', '' );
[211] Fix | Delete
row = $( '#' + new_id );
[212] Fix | Delete
} else {
[213] Fix | Delete
option_value = id;
[214] Fix | Delete
row = $( inlineEditTax.what + id );
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
// Update the value in the Parent dropdown.
[218] Fix | Delete
$( '#parent' ).find( 'option[value=' + option_value + ']' ).text( row.find( '.row-title' ).text() );
[219] Fix | Delete
[220] Fix | Delete
row.hide().fadeIn( 400, function() {
[221] Fix | Delete
// Move focus back to the Quick Edit button.
[222] Fix | Delete
row.find( '.editinline' )
[223] Fix | Delete
.attr( 'aria-expanded', 'false' )
[224] Fix | Delete
.trigger( 'focus' );
[225] Fix | Delete
wp.a11y.speak( wp.i18n.__( 'Changes saved.' ) );
[226] Fix | Delete
});
[227] Fix | Delete
[228] Fix | Delete
} else {
[229] Fix | Delete
$errorNotice.removeClass( 'hidden' );
[230] Fix | Delete
$error.html( r );
[231] Fix | Delete
/*
[232] Fix | Delete
* Some error strings may contain HTML entities (e.g. `&#8220`), let's use
[233] Fix | Delete
* the HTML element's text.
[234] Fix | Delete
*/
[235] Fix | Delete
wp.a11y.speak( $error.text() );
[236] Fix | Delete
}
[237] Fix | Delete
} else {
[238] Fix | Delete
$errorNotice.removeClass( 'hidden' );
[239] Fix | Delete
$error.text( wp.i18n.__( 'Error while saving the changes.' ) );
[240] Fix | Delete
wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) );
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
);
[244] Fix | Delete
[245] Fix | Delete
// Prevent submitting the form when pressing Enter on a focused field.
[246] Fix | Delete
return false;
[247] Fix | Delete
},
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Closes the quick edit form.
[251] Fix | Delete
*
[252] Fix | Delete
* @since 2.7.0
[253] Fix | Delete
*
[254] Fix | Delete
* @this inlineEditTax
[255] Fix | Delete
* @memberof inlineEditTax
[256] Fix | Delete
* @return {void}
[257] Fix | Delete
*/
[258] Fix | Delete
revert : function() {
[259] Fix | Delete
var id = $('table.widefat tr.inline-editor').attr('id');
[260] Fix | Delete
[261] Fix | Delete
if ( id ) {
[262] Fix | Delete
$( 'table.widefat .spinner' ).removeClass( 'is-active' );
[263] Fix | Delete
$('#'+id).siblings('tr.hidden').addBack().remove();
[264] Fix | Delete
id = id.substr( id.lastIndexOf('-') + 1 );
[265] Fix | Delete
[266] Fix | Delete
// Show the taxonomy row and move focus back to the Quick Edit button.
[267] Fix | Delete
$( this.what + id ).show().find( '.editinline' )
[268] Fix | Delete
.attr( 'aria-expanded', 'false' )
[269] Fix | Delete
.trigger( 'focus' );
[270] Fix | Delete
}
[271] Fix | Delete
},
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Retrieves the ID of the term of the element inside the table row.
[275] Fix | Delete
*
[276] Fix | Delete
* @since 2.7.0
[277] Fix | Delete
*
[278] Fix | Delete
* @memberof inlineEditTax
[279] Fix | Delete
*
[280] Fix | Delete
* @param {HTMLElement} o An element within the table row or the table row itself.
[281] Fix | Delete
* @return {string} The ID of the term based on the element.
[282] Fix | Delete
*/
[283] Fix | Delete
getId : function(o) {
[284] Fix | Delete
var id = o.tagName === 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
[285] Fix | Delete
[286] Fix | Delete
return parts[parts.length - 1];
[287] Fix | Delete
}
[288] Fix | Delete
};
[289] Fix | Delete
[290] Fix | Delete
$(document).ready(function(){inlineEditTax.init();});
[291] Fix | Delete
[292] Fix | Delete
})( jQuery, window.wp );
[293] Fix | Delete
[294] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function