' +
'
' +
thumbDiv +
'' +
fileLink +
'' +
'' +
errorMsg +
'' +
'
';
if ( 'media' === type ) {
tableDiv =
tableDiv +
'
' +
'' +
'
';
}
tableDiv = tableDiv + '
';
return tableDiv;
}
/**
* Send ajax request for single and bulk Smushing.
*/
run() {
// If bulk and we have a definite number of IDs.
if ( this.is_bulk && this.ids.length > 0 ) {
this.callAjax();
}
if ( ! this.is_bulk ) {
this.callAjax();
}
}
/**
* Show bulk Smush errors, and disable bulk Smush button on completion.
*/
bindDeferredEvents() {
const self = this;
this.deferred.done( function() {
self.button.removeAttr( 'continue_smush' );
if ( self.errors.length ) {
/** @param {string} wp_smush_msgs.error_in_bulk */
const msg = window.wp_smush_msgs.error_in_bulk
.replace( '{{errors}}', self.errors.length )
.replace( '{{total}}', self.total )
.replace( '{{smushed}}', self.smushed );
jQuery( '.wp-smush-all-done' )
.addClass( 'sui-notice-warning' )
.removeClass( 'sui-notice-success' )
.find( 'p' )
.html( msg );
}
self.bulkDone();
// Re-enable the buttons.
jQuery(
'.wp-smush-all:not(.wp-smush-finished), .wp-smush-scan'
).prop('disabled', false);
} );
}
/**
* Handles the cancel button click.
* Update the UI, and enable the bulk Smush button.
*/
cancelAjax() {
const self = this;
jQuery( '.wp-smush-cancel-bulk' ).on( 'click', function() {
// Add a data attribute to the Smush button, to stop sending ajax.
self.button.attr( 'continue_smush', false );
// Sync and update stats.
self.syncStats();
self.request.abort();
self.enableButton();
self.button.removeClass( 'wp-smush-started' );
wp_smushit_data.unsmushed.unshift( self.current_id );
jQuery( '.wp-smush-bulk-wrapper' ).removeClass( 'sui-hidden' );
// Hide the progress bar.
jQuery( '.wp-smush-bulk-progress-bar-wrapper' ).addClass( 'sui-hidden' );
} );
}
/**
* Remove the current ID from the unSmushed/re-Smush variable.
*
* @param {number} currentId
*/
static updateSmushIds( currentId ) {
if (
'undefined' !== typeof wp_smushit_data.unsmushed &&
wp_smushit_data.unsmushed.length > 0
) {
const uIndex = wp_smushit_data.unsmushed.indexOf( currentId );
if ( uIndex > -1 ) {
wp_smushit_data.unsmushed.splice( uIndex, 1 );
}
}
// Remove from the re-Smush list.
if (
'undefined' !== typeof wp_smushit_data.resmush &&
wp_smushit_data.resmush.length > 0
) {
const index = wp_smushit_data.resmush.indexOf( currentId );
if ( index > -1 ) {
wp_smushit_data.resmush.splice( index, 1 );
}
}
}
}
export default Smush;