' +
'
' + 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.call_ajax();
if ( ! this.is_bulk )
this.call_ajax();
};
/**
* Show bulk Smush errors, and disable bulk Smush button on completion.
*/
bind_deferred_events() {
const self = this;
this.deferred.done( function () {
self.button.removeAttr( 'continue_smush' );
if ( self.errors.length ) {
/** @var {string} wp_smush_msgs.error_in_bulk */
let msg = 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.bulk_done();
// Re-enable the buttons.
jQuery( '.wp-smush-all:not(.wp-smush-finished), .wp-smush-scan' ).removeAttr( 'disabled' );
} );
};
/**
* Handles the cancel button click.
* Update the UI, and enable the bulk Smush button.
*/
cancel_ajax() {
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.sync_stats();
Smush.update_stats( this.smush_type );
self.request.abort();
self.enable_button();
self.button.removeClass( 'wp-smush-started' );
wp_smushit_data.unsmushed.unshift( self.current_id );
jQuery( '.wp-smush-bulk-wrapper' ).show();
// Hide the progress bar.
jQuery( '.wp-smush-bulk-progress-bar-wrapper' ).hide();
} );
};
/**
* Remove the current ID from the unSmushed/re-Smush variable.
*
* @param current_id
*/
static update_smush_ids( current_id ) {
if ( 'undefined' !== typeof wp_smushit_data.unsmushed && wp_smushit_data.unsmushed.length > 0 ) {
const u_index = wp_smushit_data.unsmushed.indexOf( current_id );
if ( u_index > -1 ) {
wp_smushit_data.unsmushed.splice( u_index, 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( current_id );
if ( index > -1 ) {
wp_smushit_data.resmush.splice( index, 1 );
}
}
};
}
export default Smush;