: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Directory Smush module JavaScript code.
* @since 2.8.1 Separated from admin.js into dedicated file.
import { createTree } from 'jquery.fancytree';
import Scanner from '../smush/directory-scanner';
progressDialog = $( '#wp-smush-progress-dialog' );
// Make sure directory smush vars are set.
if ( typeof window.wp_smushit_data.dir_smush !== 'undefined' ) {
totalSteps = window.wp_smushit_data.dir_smush.totalSteps;
window.wp_smushit_data.dir_smush.currentScanStep;
this.scanner = new Scanner( totalSteps, currentScanStep );
* Smush translation strings.
* @param {Array} wp_smush_msgs
this.wp_smush_msgs = window.wp_smush_msgs || {};
* Open the "Select Smush directory" modal.
$( 'button.wp-smush-browse, a#smush-directory-open-modal' ).on(
if ( $( e.currentTarget ).hasClass( 'wp-smush-browse' ) ) {
$( 'div.wp-smush-scan-result div.wp-smush-notice' ).hide();
$( 'div.wp-smush-info' ).remove();
'#wp-smush-list-dialog .sui-box-header [data-modal-close]'
//Display File tree for Directory Smush
* Smush images: Smush in Choose Directory modal clicked
$( '#wp-smush-select-dir' ).on( 'click', function( e ) {
$( 'div.wp-smush-list-dialog div.sui-box-body' ).css( {
$( 'div.wp-smush-list-dialog div.sui-box-body a' ).off(
const button = $( this );
button.addClass('sui-button-onload');
const selectedFolders = self.tree.getSelectedNodes();
selectedFolders.forEach( function( folder ) {
paths.push( folder.key );
// Send a ajax request to get a list of all the image files
'input[name="image_list_nonce"]'
$.post( ajaxurl, param, function( response ) {
if ( response.success ) {
self.scanner = new Scanner( response.data, 0 );
self.showProgressDialog( response.data );
button.removeClass('sui-button-onload');
'#cancel-directory-smush, #dialog-close-div, .wp-smush-cancel-dir',
$( '.wp-smush-cancel-dir' ).addClass( 'sui-button-onload' );
self.wp_smush_msgs.directory_url )
'.sui-icon-play, .wp-smush-resume-scan',
* Check to see if we should open the directory module.
* Used to redirect from dashboard page.
const queryString = window.location.search;
const urlParams = new URLSearchParams( queryString );
if ( urlParams.has( 'start' ) && ! this.triggered ) {
$( 'button.wp-smush-browse' ).trigger( 'click' );
smushButton = $( 'button#wp-smush-select-dir' ),
action: 'smush_get_directory_list',
list_nonce: $( 'input[name="list_nonce"]' ).val(),
// Object already defined.
if ( Object.entries( self.tree ).length > 0 ) {
self.tree = createTree( '.wp-smush-list-dialog .content', {
autoCollapse: true, // Automatically collapse all siblings, when a node is expanded
clickFolderMode: 3, // 1:activate, 2:expand, 3:activate and expand, 4:activate (dblclick expands)
checkbox: true, // Show checkboxes
debugLevel: 0, // 0:quiet, 1:errors, 2:warnings, 3:infos, 4:debug
selectMode: 3, // 1:single, 2:multi, 3:multi-hier
tabindex: '0', // Whole tree behaves as one single control
keyboard: true, // Support keyboard navigation
quicksearch: true, // Navigate to next node by typing the first letters
lazyLoad: ( event, data ) => {
data.result = new Promise( function( resolve, reject ) {
ajaxSettings.data.dir = data.node.key;
.done( ( response ) => resolve( response ) )
loadChildren: ( event, data ) =>
data.node.fixSelection3AfterClick(), // Apply parent's state to new child nodes:
! +self.tree.getSelectedNodes().length
init: () => smushButton.prop( 'disabled', true ),
* @param {number} items Number of items in the scan.
showProgressDialog( items ) {
// Update items status and show the progress dialog..
$( '.wp-smush-progress-dialog .sui-progress-state-text' ).html(
'0/' + items + ' ' + self.wp_smush_msgs.progress_smushed
'wp-smush-progress-dialog',
* Update progress bar during directory smush.
* @param {number} progress Current progress in percent.
* @param {boolean} cancel Cancel status.
updateProgressBar( progress, cancel = false ) {
$( '.sui-progress-block .sui-progress-text span' ).text(
$( '.sui-progress-block .sui-progress-bar span' ).width(
$( '.sui-progress-state .sui-progress-state-text' ).text(
$( '.sui-progress-state .sui-progress-state-text' ).text(
WP_Smush.directory.init();