| 1 |
(function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names |
| 2 |
|
| 3 |
var bulkOpt; |
| 4 |
/** |
| 5 |
* Add a "Imagify'em all" in the select list. |
| 6 |
*/ |
| 7 |
bulkOpt = '<option value="imagify-bulk|optimize">' + imagifyLibrary.labels.bulkActionsOptimize + '</option>'; |
| 8 |
|
| 9 |
if ( $( '.button-imagify-optimize-missing-sizes' ).length ) { |
| 10 |
// If we have items that have missing sizes. |
| 11 |
bulkOpt += '<option value="imagify-bulk|optimize_missing_sizes">' + imagifyLibrary.labels.bulkActionsOptimizeMissingSizes + '</option>'; |
| 12 |
} |
| 13 |
|
| 14 |
if ( imagifyLibrary.backupOption || $( '.attachment-has-backup' ).length ) { |
| 15 |
// If the backup option is enabled, or if we have items that can be restored. |
| 16 |
bulkOpt += '<option value="imagify-bulk|restore">' + imagifyLibrary.labels.bulkActionsRestore + '</option>'; |
| 17 |
} |
| 18 |
|
| 19 |
$( '.bulkactions select[name="action"] option:last-child' ).before( bulkOpt ); |
| 20 |
$( '.bulkactions select[name="action2"] option:last-child' ).before( bulkOpt ); |
| 21 |
$( '#bulkaction option:last-child' ).after( bulkOpt ); |
| 22 |
|
| 23 |
/** |
| 24 |
* Process optimization for all selected images. |
| 25 |
*/ |
| 26 |
$( '#doaction' ) |
| 27 |
.add( '#doaction2' ) |
| 28 |
.add( '#bulkaction + [name="showThickbox"]' ) |
| 29 |
.on( 'click', function( e ) { |
| 30 |
var value = $( this ).prev( 'select' ).val().split( '|' ), |
| 31 |
action, ids; |
| 32 |
|
| 33 |
if ( 'imagify-bulk' !== value[0] ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
e.preventDefault(); |
| 38 |
|
| 39 |
action = value[1]; |
| 40 |
ids = $( 'input[name^="media"]:checked, input[name^="doaction"]:checked' ).map( function() { |
| 41 |
return this.value; |
| 42 |
} ).get(); |
| 43 |
|
| 44 |
ids.forEach( function( id, index ) { |
| 45 |
setTimeout( function() { |
| 46 |
$( 'table .imagify-data-actions-container[data-id="' + id + '"] .button-imagify-' + action ).first().trigger( 'click' ); |
| 47 |
}, index * 300 ); |
| 48 |
} ); |
| 49 |
} ); |
| 50 |
|
| 51 |
} )(jQuery, document, window); |
| 52 |
|