' +
w3tcData.cfWarning +
'
'
);
}
// CDN page.
if (!cdnFlushManually && w3tcData.cdnEnabled && ('cf' === w3tcData.cdnEngine || 'cf2' === w3tcData.cdnEngine)) {
// Show warning on the CDN page for flush manually.
jQuery('#cdn-flushmanually-warning').show();
} else {
// Hide warning on the CDN page for flush manually.
jQuery('#cdn-flushmanually-warning').hide();
}
}
function set_sticky_bar_positions() {
jQuery('#w3tc > #w3tc-options-menu').css(
'top',
Math.floor(
((jQuery(window).width() > 600 && jQuery('#wpadminbar').length) ? jQuery('#wpadminbar').outerHeight() : 0) +
jQuery('#w3tc-top-nav-bar').outerHeight()
)
);
jQuery('.w3tc_form_bar').css(
'top',
Math.floor(
((jQuery(window).width() > 600 && jQuery('#wpadminbar').length) ? jQuery('#wpadminbar').outerHeight() : 0) +
jQuery('#w3tc-top-nav-bar').outerHeight() +
((jQuery('#w3tc > #w3tc-options-menu').length) ? jQuery('#w3tc > #w3tc-options-menu').outerHeight() : 0)
)
);
}
function set_footer_position() {
jQuery('#w3tc-footer').insertAfter(jQuery('#wpfooter'));
jQuery('#w3tc-footer').css(
'bottom',
Math.floor(0 - jQuery('#w3tc-footer').outerHeight())
);
}
function debounce(func){
var timer;
return function(event){
if(timer){
clearTimeout(timer);
}
timer = setTimeout(func,100,event);
};
}
/**
* Get the S3 bucket region from the selected location to be used for the hostname.
*
* The default location (us-east-1) returns an empty string. All other regions return the region with a trailing dot.
*
* @since 2.7.4
*
* @param {string} location Bucket location.
* @returns string
*/
function get_bucket_region( location ) {
let region = '';
switch ( location ) {
case 'us-east-1':
break;
case 'us-east-1-e':
region = 'us-east-1.';
break;
default:
region = location + '.';
break;
}
return region;
}
/**
* Event callback for changing CDN Cloudfront (push) S3 bucket location.
*
* @since 2.7.2
*
* @see get_bucket_region()
*/
function cdn_cf_bucket_location() {
const id = jQuery( '#cdn_cf_bucket' ).val();
jQuery( '#cdn-cf-bucket-hostname' )
.text( id + '.s3.' + get_bucket_region( jQuery( '#cdn_cf_bucket_location' ).val() ) + 'amazonaws.com' );
}
/**
* Toggle the disk notice for dbcache.
*
* @since 2.8.0
*/
function toggle_dbcache_notice() {
jQuery('.dbcache_disk_notice').toggle(jQuery('#dbcache__engine').val() === 'file' && jQuery('#dbcache__enabled').is(':checked'));
}
/**
* Toggle the disk notice for objectcache.
*
* @since 2.8.0
*/
function toggle_objectcache_notice() {
jQuery('.objectcache_disk_notice').toggle(jQuery('#objectcache__engine').val() === 'file' && jQuery('#objectcache__enabled').is(':checked'));
}
/**
* Toggle the disk notice for fragmentcache.
*
* @since 2.8.0
*/
function toggle_fragmentcache_notice() {
jQuery('.fragmentcache_disk_notice').toggle(jQuery('#fragmentcache___engine').val() === 'file');
}
// On document ready.
jQuery(function() {
// Global vars.
var $cdn_enabled = jQuery('#cdn__enabled'),
$cdn_engine = jQuery('#cdn__engine');
// Database cache disk usage warning.
toggle_dbcache_notice();
jQuery('#dbcache__enabled').change(toggle_dbcache_notice);
jQuery('#dbcache__engine').change(toggle_dbcache_notice);
// Object cache disk usage warning.
toggle_objectcache_notice();
jQuery('#objectcache__enabled').change(toggle_objectcache_notice);
jQuery('#objectcache__engine').change(toggle_objectcache_notice);
// Fragment cache disk usage warning.
toggle_fragmentcache_notice();
jQuery('#fragmentcache___engine').change(toggle_fragmentcache_notice);
// General page.
jQuery('.w3tc_read_technical_info').on('click', function() {
jQuery('.w3tc_technical_info').toggle();
});
// General Settings Tab actions.
jQuery( document ).on( 'click', '.performance_page_w3tc_general .nav-tab', function(){
const $tab = jQuery( this ),
$nav_tab_wrapper = $tab.closest( ".nav-tab-wrapper" )
tab_type = $tab.attr( "data-tab-type" ),
$inside = $tab.closest( ".postbox-tabs" ).find( ".inside" );
// Highlight the selected tab.
$nav_tab_wrapper.find( "a" ).removeClass( "nav-tab-active" );
$tab.addClass( "nav-tab-active" );
// If the tab is a link, don't do anything.
if ( $tab.is('[href]') ) {
return;
}
// Start off by hiding everything.
$inside.children().hide();
if (! tab_type) {
// Show children without a data-tab-type attribute.
$inside.children(':not([data-tab-type])').show(); // Show those without data-tab-type
} else {
// Show children with the matching data-tab-type attribute.
$inside.children('[data-tab-type="' + tab_type + '"]').show();
}
} );
// Tutorial page forum links via API.
jQuery(document).on( 'click', '[data-tab-type="help"]', function() {
const $helpTab = jQuery(this),
$inside = $helpTab.closest('.postbox-tabs').find('.inside');
$forumTopicsContainer = $inside.find('.help-forum-topics');
isLoaded = $forumTopicsContainer.attr('data-loaded') === '1';
tabId = $forumTopicsContainer.attr('data-tab-id');
// Check if topics are already loaded
if (isLoaded) {
return;
}
// Fetch topics from the API
jQuery.ajax({
url: ajaxurl,
method: 'POST',
data: {
action: 'w3tc_forums_api',
_wpnonce: w3tc_nonce[0],
tabId: tabId
},
success: function(data) {
// Check for timeout
if ( data.errors && data.errors.http_request_failed ) {
$forumTopicsContainer.html('HTTP Error:', data.errors.http_request_failed);
}
// Check for empty results
else if (Array.isArray(data) && data.length === 0) {
$forumTopicsContainer.html('No forum topics found.
');
} else {
// Create a list of topics
const $ul = jQuery('