jQuery( document ).ready( function () { const { __, sprintf } = window.wp.i18n; // Set how often to check when a preload job is running const ACTIVE_INTERVAL = 3000; // Set how often to check when no preload job is running const INACTIVE_INTERVAL = 30000; // Get a reference to the log element and the previous log entry const preloadInfoPanel = jQuery( '#wpsc-preload-status' ); // Abort early if no info panel exists. if ( ! preloadInfoPanel.length ) { return; } update_preload_status( window.wpsc_preload_ajax.preload_status ); /** * Schedule the next preload status update. * * @param {number} time - time in milliseconds to wait before updating. */ function schedule_preload_update( time ) { setTimeout( () => { jQuery.post( window.wpsc_preload_ajax.ajax_url, { action: 'wpsc_get_preload_status', }, json => { if ( ! json || ! json.success ) { return; } update_preload_status( json.data ); } ); }, time ); } /** * Update displayed preload status using the provided data. * * @param {object} data - description of the preload status. */ function update_preload_status( data ) { // Bail early if no data is available. But try again in a few seconds. if ( ! data || ( ! data.running && ! data.next && ! data.previous ) ) { schedule_preload_update( ACTIVE_INTERVAL ); return; } preloadInfoPanel.empty(); let nextPreloadTime = data.running ? ACTIVE_INTERVAL : INACTIVE_INTERVAL; if ( data.running ) { const panel = jQuery( '
' ); panel.append( jQuery( '

' ).append( jQuery( '' ).text( __( 'Preloading', 'wp-super-cache' ) ) ) ); panel.append( jQuery( '

' ).text( __( 'Preloading is currently running.', 'wp-super-cache' ) ) ); const ul = panel.append( jQuery( '