: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Lazy loading functionality.
lazyloadEnableButton: document.getElementById(
lazyloadDisableButton: document.getElementById(
* Handle "Activate" button click on disabled Lazy load page.
if ( this.lazyloadEnableButton ) {
this.lazyloadEnableButton.addEventListener( 'click', ( e ) => {
e.currentTarget.classList.add( 'sui-button-onload' );
this.toggle_lazy_load( true );
* Handle "Deactivate' button click on Lazy load page.
if ( this.lazyloadDisableButton ) {
this.lazyloadDisableButton.addEventListener( 'click', ( e ) => {
e.currentTarget.classList.add( 'sui-button-onload' );
this.toggle_lazy_load( false );
* Handle "Remove icon" button click on Lazy load page.
* This removes the image from the upload placeholder.
const removeSpinner = document.getElementById(
removeSpinner.addEventListener( 'click', ( e ) => {
const removePlaceholder = document.getElementById(
'smush-remove-placeholder'
if ( removePlaceholder ) {
removePlaceholder.addEventListener( 'click', ( e ) => {
this.removeLoaderIcon( 'placeholder' );
* Handle "Remove" icon click.
* This removes the select icon from the list (not same as above functions).
const items = document.querySelectorAll( '.smush-ll-remove' );
if ( items && 0 < items.length ) {
items.forEach( function( el ) {
el.addEventListener( 'click', ( e ) => {
e.target.closest( 'li' ).style.display = 'none';
this.handlePredefinedPlaceholders();
* Handle background color changes for the two predefined placeholders.
handlePredefinedPlaceholders() {
const pl1 = document.getElementById( 'placeholder-icon-1' );
pl1.addEventListener( 'click', () => this.changeColor( '#F3F3F3' ) );
const pl2 = document.getElementById( 'placeholder-icon-2' );
pl2.addEventListener( 'click', () => this.changeColor( '#333333' ) );
document.getElementById( 'smush-color-picker' ).value = color;
document.querySelector( '.sui-colorpicker-hex .sui-colorpicker-value > span > span' ).style.backgroundColor = color;
document.querySelector( '.sui-colorpicker-hex .sui-colorpicker-value > input' ).value = color;
toggle_lazy_load( enable ) {
const nonceField = document.getElementsByName(
const xhr = new XMLHttpRequest();
ajaxurl + '?action=smush_toggle_lazy_load',
'application/x-www-form-urlencoded'
if ( 200 === xhr.status ) {
const res = JSON.parse( xhr.response );
if ( 'undefined' !== typeof res.success && res.success ) {
WP_Smush.helpers.redirectToPage( 'lazy-load' );
} else if ( 'undefined' !== typeof res.data.message ) {
WP_Smush.helpers.showErrorNotice( res.data.message );
document.querySelector( '.sui-button-onload' ).classList.remove( 'sui-button-onload' );
WP_Smush.helpers.showErrorNotice( 'Request failed. Returned status of ' + xhr.status );
document.querySelector( '.sui-button-onload' ).classList.remove( 'sui-button-onload' );
'param=' + enable + '&_ajax_nonce=' + nonceField[ 0 ].value
* Add lazy load spinner icon.
* @param {string} type Accepts: spinner, placeholder.
addLoaderIcon( type = 'spinner' ) {
// If the media frame already exists, reopen it.
// Create a new media frame
title: 'Select or upload an icon',
multiple: false, // Set to true to allow multiple files to be selected
// When an image is selected in the media frame...
frame.on( 'select', function() {
// Get media attachment details from the frame state
// Send the attachment URL to our custom image input field.
const imageIcon = document.getElementById(
'smush-' + type + '-icon-preview'
imageIcon.style.backgroundImage =
'url("' + attachment.url + '")';
imageIcon.style.display = 'block';
// Send the attachment id to our hidden input
.getElementById( 'smush-' + type + '-icon-file' )
.setAttribute( 'value', attachment.id );
// Hide the add image link
).style.display = 'none';
// Unhide the remove image link
const removeDiv = document.getElementById(
removeDiv.querySelector( 'span' ).innerHTML =
removeDiv.style.display = 'block';
// Finally, open the modal on click
* Remove lazy load spinner icon.
* @param {string} type Accepts: spinner, placeholder.
removeLoaderIcon: ( type = 'spinner' ) => {
// Clear out the preview image
const imageIcon = document.getElementById(
'smush-' + type + '-icon-preview'
imageIcon.style.backgroundImage = '';
imageIcon.style.display = 'none';
// Un-hide the add image link
document.getElementById( 'smush-upload-' + type ).style.display =
// Hide the delete image link
document.getElementById( 'smush-remove-' + type ).style.display =
// Delete the image id from the hidden input
.getElementById( 'smush-' + type + '-icon-file' )
.setAttribute( 'value', '' );
* @param {number} id Image ID.
* @param {string} type Accepts: spinner, placeholder.
remove: ( id, type = 'spinner' ) => {
const nonceField = document.getElementsByName(
const xhr = new XMLHttpRequest();
xhr.open( 'POST', ajaxurl + '?action=smush_remove_icon', true );
'application/x-www-form-urlencoded'
WP_Smush.Lazyload.init();