This commit is contained in:
2026-10-06 18:51:23 -06:00
parent 8424dacd03
commit e2c26b7f21
4223 changed files with 737986 additions and 53 deletions
File diff suppressed because one or more lines are too long
@@ -0,0 +1,691 @@
var cx_cancel_bulk_optimization=false;
var cx_pause_bulk_optimization=false;
var cx_bulk_task_running = false;
jQuery('#cx-v2-start-now').on('click', function ()
{
compressx_start_bulk_optimization();
});
jQuery('#cx-v2-cancel-bulk').on('click', function ()
{
if(cx_bulk_task_running)
{
var descript = compressx_bulk_i18n.cancel_confirm;
var ret = confirm(descript);
if(ret === true)
{
cx_cancel_bulk_optimization=true;
jQuery('#cx-v2-cancel-bulk').css({'pointer-events': 'none', 'opacity': '0.4'});
}
}
else
{
jQuery('#cx-v2-bulk-ready').show();
jQuery('#cx-v2-bulk-progress').hide();
}
});
jQuery('#cx-v2-pause-bulk').on('click', function ()
{
var descript = compressx_bulk_i18n.pause_confirm;
var ret = confirm(descript);
if(ret === true)
{
cx_pause_bulk_optimization=true;
jQuery('#cx-v2-pause-bulk').css({'pointer-events': 'none', 'opacity': '0.4'});
}
});
//
jQuery('#cx_bulk_success_hide').on('click', function ()
{
jQuery('#cx_bulk_success').hide();
jQuery('#cx-v2-bulk-ready').show();
jQuery('#cx-v2-bulk-progress').hide();
});
jQuery('#cx_bulk_error_hide').on('click', function ()
{
jQuery('#cx_bulk_error').hide();
jQuery('#cx-v2-bulk-ready').show();
jQuery('#cx-v2-bulk-progress').hide();
});
jQuery('#cx-v2-log-copy').on('click', function() {
var logContent = jQuery('#cx-v2-live-log').text();
if (logContent)
{
// Check if Clipboard API is available
if (navigator.clipboard && navigator.clipboard.writeText)
{
navigator.clipboard.writeText(logContent).then(function()
{
alert('Log copied to clipboard!');
}).catch(function() {
// Fallback if clipboard API fails
});
}
else
{
// Use fallback for non-HTTPS or unsupported browsers
}
}
});
jQuery('#cx-v2-log-download').on('click', function()
{
location.href =ajaxurl+'?_wpnonce='+compressx_ajax_object.ajax_nonce+'&action=compressx_download_task_log';
});
var currentLogFilename='';
jQuery('.cx-log-details').on('click', function(e)
{
e.preventDefault();
var logFilename = jQuery(this).data('log');
compressx_open_log_details(logFilename);
});
function compressx_open_log_details(logFilename)
{
var ajax_data = {
action: 'compressx_open_log',
filename: logFilename
};
compressx_post_request(ajax_data, function(response)
{
try {
response = JSON.parse(response);
if (response.result === 'success')
{
currentLogFilename = logFilename;
jQuery('#cx-v2-log-content').val(response.data);
jQuery('#cx-v2-log-created-date').text(response.create || '--');
jQuery('#cx-v2-log-modal').show();
jQuery('html, body').animate({
scrollTop: jQuery('#cx-v2-log-modal').offset().top - 100
}, 500);
} else {
alert('Failed to open log: ' + (response.error || 'Unknown error'));
}
} catch(err) {
alert('An error occurred while opening log.');
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
var error_message = compressx_output_ajaxerror('opening log', textStatus, errorThrown);
alert(error_message);
});
}
jQuery('.cx-log-download').on('click', function(e)
{
e.preventDefault();
var logFilename = jQuery(this).data('log');
var download_url = ajaxurl +
'?action=compressx_download_log&log=' +
logFilename +
'&nonce=' + compressx_ajax_object.ajax_nonce;
window.location.href = download_url;
});
jQuery('.cx-log-delete').on('click', function(e)
{
e.preventDefault();
var logFilename = jQuery(this).data('log');
var $element= jQuery(this);
if (!confirm(compressx_bulk_i18n.delete_log_confirm))
{
return;
}
var ajax_data = {
action: 'compressx_delete_log',
filename: logFilename
};
compressx_post_request(ajax_data, function(response) {
try {
response = JSON.parse(response);
if (response.result === 'success') {
$element.closest('tr').fadeOut(function() {
jQuery(this).remove();
});
} else {
alert('Failed to delete log: ' + (response.error || 'Unknown error'));
}
} catch(err) {
alert('An error occurred while deleting log.');
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
var error_message = compressx_output_ajaxerror('deleting log', textStatus, errorThrown);
alert(error_message);
});
});
jQuery('#cx-v2-download-current-log').on('click', function()
{
//currentLogFilename
if (currentLogFilename === "")
{
return;
}
var download_url = ajaxurl +
'?action=compressx_download_log&log=' +
currentLogFilename +
'&nonce=' + compressx_ajax_object.ajax_nonce;
window.location.href = download_url;}
);
jQuery('#cx-v2-close-log').on('click', function(e)
{
jQuery('#cx-v2-log-modal').hide();
currentLogFilename = '';
});
function compressx_start_bulk_optimization()
{
var force="0";
if(jQuery('#cx-v2-force-reprocess').prop('checked'))
{
force = '1';
}
else {
force = '0';
}
var ajax_data = {
'action': 'compressx_start_scan_unoptimized_image',
'force':force
};
cx_cancel_bulk_optimization=false;
jQuery('#cx-v2-cancel-bulk').css({'pointer-events': 'auto', 'opacity': '1'});
cx_pause_bulk_optimization=false;
jQuery('#cx-v2-pause-bulk').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#cx-v2-bulk-ready').hide();
jQuery('#cx-v2-bulk-progress').show();
compressx_reset_bulk_progress();
cx_bulk_task_running=true;
compressx_post_request(ajax_data, function (data)
{
if(cx_cancel_bulk_optimization)
{
compressx_bulk_optimization_canceled();
return;
}
if(cx_pause_bulk_optimization)
{
compressx_bulk_optimization_paused();
return;
}
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
if(jsonarray.finished==true)
{
compressx_update_bulk_scan_progress(jsonarray.progress_text,jsonarray.progress_percent);
compressx_init_bulk_optimization_task();
}
else
{
compressx_update_bulk_scan_progress(jsonarray.progress_text,jsonarray.progress_percent);
compressx_scanning_images(jsonarray.offset);
}
}
else
{
compressx_progress_error(jsonarray.error);
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
var error_message = compressx_output_ajaxerror('scanning images', textStatus, errorThrown);
compressx_progress_error(error_message);
});
}
function compressx_scanning_images(offset)
{
var force="0";
if(jQuery('#cx-v2-force-reprocess').prop('checked'))
{
force = '1';
}
else {
force = '0';
}
var ajax_data = {
'action': 'compressx_start_scan_unoptimized_image',
'force':force,
'offset':offset
};
cx_cancel_bulk_optimization=false;
compressx_post_request(ajax_data, function (data)
{
if(cx_cancel_bulk_optimization)
{
compressx_bulk_optimization_canceled();
return;
}
if(cx_pause_bulk_optimization)
{
compressx_bulk_optimization_paused();
return;
}
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
if(jsonarray.finished==true)
{
compressx_update_bulk_scan_progress(jsonarray.progress_text,jsonarray.progress_percent);
compressx_init_bulk_optimization_task();
}
else
{
compressx_update_bulk_scan_progress(jsonarray.progress_text,jsonarray.progress_percent);
compressx_scanning_images(jsonarray.offset);
}
}
else
{
compressx_progress_error(jsonarray.error);
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
var error_message = compressx_output_ajaxerror('scanning images', textStatus, errorThrown);
compressx_progress_error(error_message);
});
}
function compressx_init_bulk_optimization_task()
{
var force="0";
if(jQuery('#cx-v2-force-reprocess').prop('checked'))
{
force = '1';
}
else {
force = '0';
}
var ajax_data = {
'action': 'compressx_init_bulk_optimization_task',
'force':force
};
compressx_post_request(ajax_data, function (data)
{
if(cx_cancel_bulk_optimization)
{
compressx_bulk_optimization_canceled();
return;
}
if(cx_pause_bulk_optimization)
{
compressx_bulk_optimization_paused();
return;
}
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
compressx_get_task_log();
compressx_run_optimize();
}
else
{
if(jsonarray.no_unoptimized_images)
{
compressx_progress_finish(jsonarray.error,"Optimization Status:");
}
else
{
compressx_progress_error(jsonarray.error);
}
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
var error_message = compressx_output_ajaxerror('start bulk optimization', textStatus, errorThrown);
compressx_progress_error(error_message);
});
}
function compressx_run_optimize()
{
var ajax_data = {
'action': 'compressx_run_optimize',
};
compressx_post_request(ajax_data, function (data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
setTimeout(function ()
{
compressx_get_optimize_task_status();
}, 1000);
}
else
{
compressx_progress_error(jsonarray.error);
}
}
catch(err)
{
setTimeout(function ()
{
compressx_get_optimize_task_status();
}, 1000);
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
compressx_get_optimize_task_status();
});
}
function compressx_get_optimize_task_status()
{
var ajax_data = {
'action': 'compressx_get_opt_progress'
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
//progress_text,progress_percent,sub_progress_text,sub_progress_percent,optimized,errors,remaining
compressx_update_bulk_progress(jsonarray.progress_text,jsonarray.progress_percent,jsonarray.sub_progress_text,jsonarray.sub_progress_percent,jsonarray.optimized,jsonarray.errors,jsonarray.remaining);
if(jsonarray.continue)
{
setTimeout(function ()
{
compressx_get_optimize_task_status();
}, 1000);
}
else if(jsonarray.finished)
{
jQuery(document).trigger('compressx:hasUpdateImageData');
compressx_progress_finish(jsonarray.message);
compressx_show_review_box(jsonarray);
}
else
{
if(cx_cancel_bulk_optimization)
{
compressx_bulk_optimization_canceled(jsonarray.message);
return;
}
if(cx_pause_bulk_optimization)
{
compressx_bulk_optimization_paused();
return;
}
jQuery(document).trigger('compressx:hasUpdateImageData');
compressx_run_optimize();
}
}
else if (jsonarray.result === 'failed')
{
if(jsonarray.timeout)
{
if(cx_cancel_bulk_optimization)
{
compressx_bulk_optimization_canceled(jsonarray.message);
return;
}
if(cx_pause_bulk_optimization)
{
compressx_bulk_optimization_paused();
return;
}
compressx_run_optimize();
}
else
{
compressx_progress_error(jsonarray.error);
}
}
}
catch(err)
{
setTimeout(function ()
{
compressx_get_optimize_task_status();
}, 1000);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
setTimeout(function ()
{
compressx_get_optimize_task_status();
}, 1000);
});
}
function compressx_get_task_log(offset)
{
if(!cx_bulk_task_running)
return;
var ajax_data = {
'action': 'compressx_get_task_log',
'offset':offset
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
var $logContainer = jQuery('#cx-v2-live-log');
$logContainer.append(jsonarray.content);
if (jQuery('#cx-v2-log-autoscroll').is(':checked'))
{
$logContainer.scrollTop($logContainer[0].scrollHeight);
}
compressx_limit_log_lines($logContainer, 5000);
setTimeout(function ()
{
compressx_get_task_log(jsonarray.offset);
}, 3000);
}
else
{
//
}
}
catch(err)
{
setTimeout(function ()
{
compressx_get_task_log(0);
}, 3000);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
setTimeout(function ()
{
compressx_get_task_log(0);
}, 3000);
});
}
function compressx_limit_log_lines($container,maxLines)
{
var lines = $container.text().split('\n');
if (lines.length > maxLines)
{
var newLines = lines.slice(lines.length - maxLines);
$container.text(newLines.join('\n'));
}
}
function compressx_reset_bulk_progress()
{
jQuery('#cx-v2-progress-status').html("Ready");
jQuery('#cx-v2-scan-status').html("0 images scanned");
jQuery('#cx-v2-scan-progress-bar').width("0%");
jQuery('#cx-v2-overall-progress-text').html("0 images processed");
jQuery('#cx-v2-overall-progress-bar').width("0%");
jQuery('#cx-v2-job-current').html("None");
jQuery('#cx-v2-job-progress-bar').width("0%");
jQuery('#cx-v2-stat-optimized').html("0");
jQuery('#cx-v2-stat-errors').html("0");
jQuery('#cx-v2-stat-remaining').html("0");
jQuery('#cx_bulk_warning').show();
jQuery('#cx_bulk_success').hide();
jQuery('#cx_bulk_error').hide();
jQuery('#cx-v2-live-log').html("");
}
function compressx_bulk_optimization_canceled(message)
{
//jQuery('#cx-v2-bulk-ready').show();
//jQuery('#cx-v2-bulk-progress').hide();
jQuery('#cx-v2-cancel-bulk').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#cx_bulk_warning').hide();
jQuery('#cx_bulk_success').show();
jQuery('#cx_bulk_success_title').html("The process has been canceled");
jQuery('#cx_bulk_success_message').html(message);
cx_bulk_task_running=false;
}
function compressx_bulk_optimization_paused()
{
cx_pause_bulk_optimization=false;
jQuery('#cx-v2-pause-bulk').css({'pointer-events': 'auto', 'opacity': '1'});
}
function compressx_update_bulk_scan_progress(progress_text,progress_percent)
{
jQuery('#cx-v2-progress-status').html("Scanning");
jQuery('#cx-v2-scan-status').html(progress_text);
jQuery('#cx-v2-scan-progress-bar').width(progress_percent+"%");
}
function compressx_update_bulk_progress(progress_text,progress_percent,sub_progress_text,sub_progress_percent,optimized,errors,remaining)
{
jQuery('#cx-v2-progress-status').html("Running");
jQuery('#cx-v2-overall-progress-text').html(progress_text);
jQuery('#cx-v2-overall-progress-bar').width(progress_percent+"%");
jQuery('#cx-v2-job-current').html(sub_progress_text);
jQuery('#cx-v2-job-progress-bar').width(sub_progress_percent+"%");
jQuery('#cx-v2-stat-optimized').html(optimized);
jQuery('#cx-v2-stat-errors').html(errors);
jQuery('#cx-v2-stat-remaining').html(remaining);
}
function compressx_progress_finish(message,title=compressx_bulk_i18n.optimization_success)
{
//jQuery('#cx-v2-bulk-ready').show();
//jQuery('#cx-v2-bulk-progress').hide();
jQuery('#cx_bulk_warning').hide();
jQuery('#cx_bulk_success').show();
jQuery('#cx_bulk_success_title').html(title);
jQuery('#cx_bulk_success_message').html(message);
cx_bulk_task_running=false;
}
function compressx_progress_error(message)
{
//jQuery('#cx-v2-bulk-ready').show();
//jQuery('#cx-v2-bulk-progress').hide();
jQuery('#cx_bulk_warning').hide();
jQuery('#cx_bulk_error').show();
jQuery('#cx_bulk_error_title').html("Error: Optimization Failed");
jQuery('#cx_bulk_error_message').html(message);
cx_bulk_task_running=false;
}
function compressx_show_review_box(jsonarray)
{
if(jsonarray.show_review)
{
jQuery('#cx_rating_box').show();
jQuery('#cx_size_of_opt_images').html(jsonarray.opt_size);
}
}
window.addEventListener('click', function(e)
{
if(cx_bulk_task_running && e.target.matches('a')){
if(!confirm(compressx_bulk_i18n.leave_page_confirm))
{
e.preventDefault();
}
}
});
window.addEventListener("beforeunload", function (e) {
if (cx_bulk_task_running)
{
e.preventDefault();
e.returnValue = "Leaving this page will interrupt the optimization task.";
return "Leaving this page will interrupt the optimization task.";
}
});
@@ -0,0 +1,115 @@
jQuery(document).ready(function($) {
$('#compressx_save_cdn').click(function() {
compressx_save_cdn_setting();
});
$('#compressx_purge_cache').click(function() {
compressx_purge_cache();
});
$('#compressx_cdn_provider').on('change', function() {
var provider = $(this).val();
if (provider === 'cloudflare') {
$('#cloudflare_container').show();
$('#bunnycdn_container').hide();
} else if (provider === 'bunnycdn') {
$('#cloudflare_container').hide();
$('#bunnycdn_container').show();
}
});
$(document).trigger('compressx_cdn_v2_js_ready');
});
function compressx_save_cdn_setting() {
var json = {};
var option_type = 'cf_cdn';
var action_name = 'compressx_save_cdn';
var save_override = jQuery(document).triggerHandler('compressx_cdn_v2_save_override');
if (save_override) {
return save_override;
}
var setting_data = compressx_ajax_data_transfer(option_type);
var json1 = JSON.parse(setting_data);
jQuery.extend(json1, json);
setting_data = JSON.stringify(json1);
var ajax_data = {
'action': action_name,
'setting': setting_data,
};
jQuery('#compressx_save_cdn').css({'pointer-events': 'none', 'opacity': '0.4'});
jQuery('#compressx_save_cdn_progress').show();
compressx_post_request(ajax_data, function (data) {
try {
var jsonarray = jQuery.parseJSON(data);
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#compressx_save_cdn_progress').hide();
if (jsonarray.result === 'success') {
jQuery('#compressx_save_cdn_text').removeClass("hidden");
setTimeout(function () {
jQuery('#compressx_save_cdn_text').addClass('hidden');
}, 3000);
} else {
alert(jsonarray.error);
}
} catch (err) {
alert(err);
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#compressx_save_cdn_progress').hide();
}
}, function (XMLHttpRequest, textStatus, errorThrown) {
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#compressx_save_cdn_progress').hide();
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
alert(error_message);
});
}
function compressx_purge_cache() {
var json = {};
var setting_data = compressx_ajax_data_transfer('cf_cdn');
var json1 = JSON.parse(setting_data);
jQuery.extend(json1, json);
setting_data = JSON.stringify(json1);
var ajax_data = {
'action': 'compressx_purge_cache',
'setting': setting_data,
};
jQuery('#compressx_purge_cache').css({'pointer-events': 'none', 'opacity': '0.4'});
jQuery('#compressx_purge_cache_progress').show();
compressx_post_request(ajax_data, function (data) {
jQuery('#compressx_purge_cache_progress').hide();
try {
var jsonarray = jQuery.parseJSON(data);
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
if (jsonarray.result === 'success') {
jQuery('#compressx_purge_cache_text').removeClass("hidden");
setTimeout(function () {
jQuery('#compressx_purge_cache_text').addClass('hidden');
}, 3000);
} else {
alert(jsonarray.error);
}
} catch (err) {
alert(err);
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
}
}, function (XMLHttpRequest, textStatus, errorThrown) {
jQuery('#compressx_purge_cache_progress').hide();
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
alert(error_message);
});
}
@@ -0,0 +1,337 @@
//
let isHoveringComparison = false;
let hasUpdateImageData=false;
let latestImageData = null;
let currentComparisonMode = 'webp';
jQuery('#cx-v2-bulk-comparison-container').on('mouseenter', function()
{
isHoveringComparison = true;
}).on('mouseleave', function() {
isHoveringComparison = false;
});
jQuery('#cx-v2-bulk-show-webp').on('click', function () {
switchComparisonMode('webp');
});
jQuery('#cx-v2-bulk-show-avif').on('click', function () {
switchComparisonMode('avif');
});
jQuery('#cx-v2-bulk-show-formats').on('click', function () {
switchComparisonMode('formats');
});
function resetComparison()
{
var $container = jQuery('#cx-v2-bulk-comparison-container');
// Use the dedicated destroy function
destroyComparison($container);
// Reset opacity and add placeholder
$container.css('opacity', '1');
$container.append('<div class="cx-comparison-placeholder"><span class="compressx-v2-text-gray-500 compressx-v2-text-sm">Comparison will appear here during optimization</span></div>');
jQuery('#cx-v2-bulk-format-toggle').hide();
// Reset comparison buttons to default state
updateComparisonButtons(currentComparisonMode);
jQuery('#cx-v2-original-size').text('--');
jQuery('#cx-v2-webp-size').text('--');
jQuery('#cx-v2-webp-savings').text('');
jQuery('#cx-v2-avif-size').text('--');
jQuery('#cx-v2-avif-savings').text('');
latestImageData = null;
}
function destroyComparison($container) {
if ($container.hasClass('twentytwenty-container')) {
$container.off('.twentytwenty');
$container.removeClass('twentytwenty-container');
}
$container.empty();
}
function switchComparisonMode(mode)
{
currentComparisonMode = mode;
updateComparisonButtons(mode);
if (latestImageData) {
renderComparison(latestImageData, mode);
}
}
function updateComparisonButtons(activeMode)
{
jQuery('#cx-v2-bulk-show-webp, #cx-v2-bulk-show-avif, #cx-v2-bulk-show-formats')
.removeClass('hover:compressx-v2-bg-gray-100 compressx-v2-bg-green-500 compressx-v2-text-white compressx-v2-border-green-500')
.addClass('compressx-v2-bg-gray-50 compressx-v2-text-gray-700 compressx-v2-border-gray-300');
var activeButton = null;
if (activeMode === 'webp') {
activeButton = '#cx-v2-bulk-show-webp';
} else if (activeMode === 'avif') {
activeButton = '#cx-v2-bulk-show-avif';
} else if (activeMode === 'formats') {
activeButton = '#cx-v2-bulk-show-formats';
}
if (activeButton)
{
jQuery(activeButton)
.removeClass('compressx-v2-bg-gray-50 compressx-v2-text-gray-700 compressx-v2-border-gray-300')
.addClass('compressx-v2-bg-green-500 compressx-v2-text-white compressx-v2-border-green-500');
}
}
function renderComparison(imageData, mode)
{
var $container = jQuery('#cx-v2-bulk-comparison-container');
$container.css({
'opacity': '0',
'transition': 'opacity 0.3s ease'
});
// Completely destroy and rebuild the comparison container
destroyComparison($container);
var beforeImg, afterImg, beforeLabel, afterLabel;
var hasWebP = imageData.webp_url && !imageData.webp_disabled;
var hasAVIF = imageData.avif_url && !imageData.avif_disabled;
// Determine which buttons to show and default mode
var showToggle = hasWebP && hasAVIF;
var availableModes = [];
if (hasWebP) availableModes.push('webp');
if (hasAVIF) availableModes.push('avif');
if (hasWebP && hasAVIF) availableModes.push('formats');
// Update button visibility
jQuery('#cx-v2-bulk-show-webp').toggle(hasWebP && hasAVIF);
jQuery('#cx-v2-bulk-show-avif').toggle(hasWebP && hasAVIF);
jQuery('#cx-v2-bulk-show-formats').toggle(hasWebP && hasAVIF);
// Show or hide the toggle container
if (showToggle) {
jQuery('#cx-v2-bulk-format-toggle').show();
} else {
jQuery('#cx-v2-bulk-format-toggle').hide();
}
// Auto-select appropriate mode if current mode is not available
if (!availableModes.includes(mode)) {
mode = availableModes[0] || 'webp';
currentComparisonMode = mode;
updateComparisonButtons(mode);
}
if (mode === 'webp' && hasWebP) {
beforeImg = imageData.original_url;
afterImg = imageData.webp_url;
beforeLabel = 'Original';
afterLabel = 'WebP';
} else if (mode === 'avif' && hasAVIF) {
beforeImg = imageData.original_url;
afterImg = imageData.avif_url;
beforeLabel = 'Original';
afterLabel = 'AVIF';
} else if (mode === 'formats' && hasWebP && hasAVIF) {
beforeImg = imageData.webp_url;
afterImg = imageData.avif_url;
beforeLabel = 'WebP';
afterLabel = 'AVIF';
} else {
$container.append('<div class="cx-comparison-placeholder"><span class="compressx-v2-text-gray-500 compressx-v2-text-sm">Comparison not available for this mode</span></div>');
$container.css('opacity', '1');
return;
}
$container.append('<img src="' + beforeImg + '" />');
$container.append('<img src="' + afterImg + '" />');
reinitializeTwentyTwenty($container, function() {
$container.css('opacity', '1');
}, beforeLabel, afterLabel);
}
function updateComparisonData(imageData) {
if (isHoveringComparison) {
return;
}
latestImageData = imageData;
if (imageData.original_size) {
jQuery('#cx-v2-original-size').text(imageData.original_size);
}
if (imageData.webp_url && !imageData.webp_disabled)
{
jQuery('#cx-v2-webp-size').text(imageData.webp_size || '--');
jQuery('#cx-v2-webp-savings').text(imageData.webp_savings || '');
}
else {
jQuery('#cx-v2-webp-size').text('--');
jQuery('#cx-v2-webp-savings').text('');
}
if (imageData.avif_url && !imageData.avif_disabled)
{
jQuery('#cx-v2-avif-size').text(imageData.avif_size || '--');
jQuery('#cx-v2-avif-savings').text(imageData.avif_savings || '');
}
else {
jQuery('#cx-v2-avif-size').text('--');
jQuery('#cx-v2-avif-savings').text('');
}
// Determine appropriate comparison mode based on available formats
var hasWebP = imageData.webp_url && !imageData.webp_disabled;
var hasAVIF = imageData.avif_url && !imageData.avif_disabled;
var targetMode = currentComparisonMode;
// Auto-switch to available format if current mode is not available
if (currentComparisonMode === 'webp' && !hasWebP && hasAVIF) {
targetMode = 'avif';
} else if (currentComparisonMode === 'avif' && !hasAVIF && hasWebP) {
targetMode = 'webp';
} else if (currentComparisonMode === 'formats' && !(hasWebP && hasAVIF)) {
targetMode = hasWebP ? 'webp' : 'avif';
} else if (!hasWebP && !hasAVIF) {
// No formats available
targetMode = 'webp'; // Fallback
} else if (hasWebP && currentComparisonMode !== 'avif' && currentComparisonMode !== 'formats') {
targetMode = 'webp';
} else if (hasAVIF && !hasWebP) {
targetMode = 'avif';
}
if (targetMode !== currentComparisonMode) {
currentComparisonMode = targetMode;
}
renderComparison(imageData, currentComparisonMode);
}
function reinitializeTwentyTwenty($container, callback, beforeLabel, afterLabel) {
var images = $container.find('img');
var loadedCount = 0;
var totalImages = images.length;
if (totalImages === 0) {
if (callback) callback();
return;
}
images.off('load.cxcmp').on('load.cxcmp', function () {
loadedCount++;
if (loadedCount !== totalImages) return;
setTimeout(function () {
if (typeof jQuery.fn.twentytwenty !== 'function') {
if (callback) callback();
return;
}
var options = {
default_offset_pct: 0.5,
move_slider_on_hover: false,
move_with_handle_only: true,
click_to_move: false,
no_overlay: false,
before_label: beforeLabel || 'Before',
after_label: afterLabel || 'After'
};
var $img = $container.find('img').first();
var naturalW = $img[0]?.naturalWidth || 0;
if (naturalW) {
$container.css({
maxWidth: naturalW + 'px',
marginLeft: 'auto',
marginRight: 'auto'
});
}
$container.twentytwenty(options);
$container.find('img').css({
'max-width': '100%',
'height': 'auto',
'width': '100%',
'display': 'block'
});
var raf = window.requestAnimationFrame || function (fn) { return setTimeout(fn, 0); };
raf(async function () {
jQuery(window).trigger('resize.twentytwenty');
callback && callback();
});
}, 0);
});
images.each(function () {
if (this.complete && this.naturalHeight !== 0) {
jQuery(this).trigger('load.cxcmp');
}
});
}
function init_latestImageData()
{
var ajax_data = {
action: 'compressx_get_latest_image_data',
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = JSON.parse(data);
if (jsonarray.result === 'success')
{
updateComparisonData(jsonarray.current_image);
}
else
{
resetComparison();
}
}
catch (err)
{
resetComparison();
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
resetComparison();
});
}
function autoRefreshLatestImageData()
{
if(!isHoveringComparison&&hasUpdateImageData)
{
init_latestImageData();
hasUpdateImageData = false;
}
setTimeout(autoRefreshLatestImageData, 10000);
}
jQuery(document).on('compressx:hasUpdateImageData', function () {
hasUpdateImageData = true;
});
jQuery(document).ready(function ($)
{
init_latestImageData();
autoRefreshLatestImageData();
});
@@ -0,0 +1,455 @@
jQuery('#cx_hide_big_update').click(function()
{
jQuery('#cx_big_update').hide();
var ajax_data = {
'action': 'compressx_hide_big_update_v2',
};
compressx_post_request(ajax_data, function(data)
{
}, function(XMLHttpRequest, textStatus, errorThrown) {
});
});
jQuery('#cx_show_size_threshold_tip').on('click', function()
{
jQuery('#cx_size_threshold_tip').slideToggle(150);
});
jQuery('input:radio[name=compression_mode]').click(function(e)
{
if(jQuery(this).prop('checked'))
{
//var $saveButton = jQuery("#cx-v2-save-settings");
let value = jQuery(this).prop('value');
if(value==='smart')
{
//$saveButton.css({ 'pointer-events': 'none', 'opacity': '0.4' });
jQuery("#compressx_general_quality_setting").hide();
jQuery("#compressx_smart_quality_setting").show();
jQuery("#cx_compression_mode_smart").closest('label').addClass('compressx-v2-bg-white');
jQuery("#cx_compression_mode_general").closest('label').removeClass('compressx-v2-bg-white');
}
else if(value==='general')
{
//$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery("#compressx_general_quality_setting").show();
jQuery("#compressx_smart_quality_setting").hide();
jQuery("#cx_compression_mode_general").closest('label').addClass('compressx-v2-bg-white');
jQuery("#cx_compression_mode_smart").closest('label').removeClass('compressx-v2-bg-white');
}
}
});
jQuery('#cx_convert_to_webp').click(function()
{
var value = '0';
if(jQuery('#cx_convert_to_webp').prop('checked'))
{
value = '1';
var descript = compressx_image_optimization_i18n.enable_webp_confirm;
}
else {
value = '0';
var descript = compressx_image_optimization_i18n.disable_webp_confirm;
}
var ret = confirm(descript);
if(ret === false)
{
if(jQuery('#cx_convert_to_webp').prop('checked'))
{
jQuery('#cx_convert_to_webp').prop('checked', false);
}
else
{
jQuery('#cx_convert_to_webp').prop('checked', true);
}
}
else
{
if(jQuery('#cx_convert_to_webp').prop('checked'))
{
jQuery('#cx_convert_to_webp').parent('label').addClass('compressx-v2-bg-white');
}
else
{
jQuery('#cx_convert_to_webp').parent('label').removeClass('compressx-v2-bg-white');
}
}
});
jQuery('#cx_convert_to_avif').click(function()
{
var value = '0';
if(jQuery('#cx_convert_to_avif').prop('checked'))
{
if(jQuery('#cx_converter_method_imagick').prop('checked'))
{
if(compressx_alert.imagick_avif)
{
var descript = compressx_image_optimization_i18n.imagick6_avif_warning;
}
else
{
var descript = compressx_image_optimization_i18n.enable_avif_confirm;
}
}
else
{
var descript = compressx_image_optimization_i18n.enable_avif_confirm;
}
value = '1';
}
else {
value = '0';
var descript = compressx_image_optimization_i18n.disable_avif_confirm;
}
var ret = confirm(descript);
if(ret === false)
{
if(jQuery('#cx_convert_to_avif').prop('checked'))
{
jQuery('#cx_convert_to_avif').prop('checked', false);
}
else
{
jQuery('#cx_convert_to_avif').prop('checked', true);
}
}
else
{
if(jQuery('#cx_convert_to_avif').prop('checked'))
{
jQuery('#cx_convert_to_avif').parent('label').addClass('compressx-v2-bg-white');
}
else
{
jQuery('#cx_convert_to_avif').parent('label').removeClass('compressx-v2-bg-white');
}
}
});
jQuery('#cx_converter_method_gd').click(function()
{
if(jQuery('#cx_converter_method_gd').prop('checked'))
{
jQuery('#cx_converter_method_gd').parent('label').addClass('compressx-v2-bg-white');
}
else
{
jQuery('#cx_converter_method_gd').parent('label').removeClass('compressx-v2-bg-white');
}
if(compressx_alert.support_gd_webp)
{
jQuery('#cx_convert_to_webp').prop('disabled', false);
jQuery('#cx_webp_status').removeClass("compressx-v2-text-red-600");
jQuery('#cx_webp_status').addClass("compressx-v2-text-green-600");
jQuery('#cx_webp_status').html(compressx_image_optimization_i18n.supported);
}
else
{
jQuery('#cx_convert_to_webp').prop('disabled', true);
jQuery('#cx_webp_status').addClass("compressx-v2-text-red-600");
jQuery('#cx_webp_status').removeClass("compressx-v2-text-green-600");
jQuery('#cx_webp_status').html(compressx_image_optimization_i18n.unsupported);
}
if(compressx_alert.support_gd_avif)
{
jQuery('#cx_convert_to_avif').prop('disabled', false);
jQuery('#cx_avif_status').removeClass("compressx-v2-text-red-600");
jQuery('#cx_avif_status').addClass("compressx-v2-text-green-600");
jQuery('#cx_avif_status').html(compressx_image_optimization_i18n.supported);
}
else
{
jQuery('#cx_convert_to_avif').prop('disabled', true);
jQuery('#cx_avif_status').addClass("compressx-v2-text-red-600");
jQuery('#cx_avif_status').removeClass("compressx-v2-text-green-600");
jQuery('#cx_avif_status').html(compressx_image_optimization_i18n.unsupported);
}
});
jQuery('#cx_converter_method_imagick').click(function()
{
if(jQuery('#cx_converter_method_imagick').prop('checked'))
{
jQuery('#cx_converter_method_imagick').parent('label').addClass('compressx-v2-bg-white');
}
else
{
jQuery('#cx_converter_method_imagick').parent('label').removeClass('compressx-v2-bg-white');
}
if(compressx_alert.support_imagick_webp)
{
jQuery('#cx_convert_to_webp').prop('disabled', false);
jQuery('#cx_webp_status').removeClass("compressx-v2-text-red-600");
jQuery('#cx_webp_status').addClass("compressx-v2-text-green-600");
jQuery('#cx_webp_status').html(compressx_image_optimization_i18n.supported);
}
else
{
jQuery('#cx_convert_to_webp').prop('disabled', true);
jQuery('#cx_webp_status').addClass("compressx-v2-text-red-600");
jQuery('#cx_webp_status').removeClass("compressx-v2-text-green-600");
jQuery('#cx_webp_status').html(compressx_image_optimization_i18n.unsupported);
}
if(compressx_alert.support_imagick_avif)
{
jQuery('#cx_convert_to_avif').prop('disabled', false);
jQuery('#cx_avif_status').removeClass("compressx-v2-text-red-600");
jQuery('#cx_avif_status').addClass("compressx-v2-text-green-600");
jQuery('#cx_avif_status').html(compressx_image_optimization_i18n.supported);
}
else
{
jQuery('#cx_convert_to_avif').prop('disabled', true);
jQuery('#cx_avif_status').addClass("compressx-v2-text-red-600");
jQuery('#cx_avif_status').removeClass("compressx-v2-text-green-600");
jQuery('#cx_avif_status').html("Unsupported");
}
});
jQuery('#cx_start_bulk_optimization').click(function()
{
let params = new URLSearchParams(window.location.search);
params.set('view', 'bulk');
window.location.href = window.location.pathname + '?' + params.toString();
});
jQuery('#cx_start_bulk_optimization_2').click(function()
{
let params = new URLSearchParams(window.location.search);
params.set('view', 'bulk');
window.location.href = window.location.pathname + '?' + params.toString();
});
jQuery('#cx-v2-save-settings').click(function(e)
{
e.preventDefault();
var $saveButton = jQuery(this);
$saveButton.css({ 'pointer-events': 'none', 'opacity': '0.4' });
jQuery('#cx-v2-save-settings-progress').show();
var json = {};
if(jQuery('#cx_convert_to_webp').prop('checked'))
{
json['convert_to_webp'] ='1';
}
else
{
json['convert_to_webp'] ='0';
}
if(jQuery('#cx_convert_to_avif').prop('checked'))
{
json['convert_to_avif'] ='1';
}
else
{
json['convert_to_avif'] ='0';
}
if(jQuery('#cx_converter_method_gd').prop('checked'))
{
json['converter_method'] = 'gd';
}
else if(jQuery('#cx_converter_method_imagick').prop('checked'))
{
json['converter_method'] = 'imagick';
}
else
{
json['converter_method'] = '';
}
json['auto_optimize'] = jQuery('#cx_enable_auto_optimize').attr('data-checked');
json['interface_version']= jQuery('input[name="cx-v2-interface-version"]:checked').val();
json['image_load']= jQuery('input[name="cx-v2-browser"]:checked').val();
json['resize']=jQuery('#cx-v2-resize-enable').attr('data-checked') === '1';
json['resize_width']=jQuery('#cx-v2-resize-width').val();
json['resize_height']=jQuery('#cx-v2-resize-height').val();
json['remove_exif']=jQuery('input[name="cx-v2-exif"]:checked').val() === 'strip';
json['auto_remove_larger_format']=jQuery('#cx-v2-avoid-larger').attr('data-checked') === '1';
json['exclude_png']=jQuery('#cx-v2-exclude-png').is(':checked');
json['exclude_png_webp'] =jQuery('#cx-v2-exclude-png-webp').is(':checked');
json['converter_images_pre_request'] =jQuery('#cx-v2-throughput').val();
json['quality_webp']=jQuery('#cx-v2-webp-quality-input').val();
json['quality_avif']=jQuery('#cx-v2-avif-quality-input').val();
if (json['quality_webp'] < 1 || json['quality_webp'] > 100) {
alert('WebP Quality must be between 1 and 99.');
return;
}
if ( json['quality_avif'] < 1 || json['quality_avif'] > 100) {
alert('AVIF Quality must be between 1 and 99.');
return;
}
var ajax_data = {
'action': 'compressx_save_image_optimization_settings',
'settings': JSON.stringify(json),
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = JSON.parse(data);
if (jsonarray.result === 'success')
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
jQuery('#cx-v2-save-settings-text').removeClass('compressx-v2-hidden');
setTimeout(function() {
jQuery('#cx-v2-save-settings-text').addClass('compressx-v2-hidden');
}, 3000);
if(jsonarray.interface_version_changed===true)
{
location.reload();
}
}
else
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
alert(jsonarray.error || 'Failed to save settings.');
}
}
catch (err)
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
alert('An error occurred while saving settings.');
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
var error_message = compressx_output_ajaxerror('saving settings', textStatus, errorThrown);
alert(error_message);
});
});
jQuery('#cx_enable_auto_optimize').on('click', function()
{
updateAutoOptimizeSwitch();
});
jQuery('#cx-v2-free-toggle-advanced').click(function(e)
{
e.preventDefault();
var advancedArrow = jQuery('#cx-v2-free-advanced-arrow');
var advancedSection = jQuery('#cx-v2-free-advanced-section');
var isHidden =advancedSection.css('display') === 'none';
if (isHidden)
{
advancedSection.slideDown(300);
advancedArrow.removeClass('dashicons-arrow-right').addClass('dashicons-arrow-down');
}
else
{
advancedSection.slideUp(300);
advancedArrow.removeClass('dashicons-arrow-down').addClass('dashicons-arrow-right');
}
});
jQuery('.cx-v2-tab-btn').click(function(e)
{
e.preventDefault();
var $btn = jQuery(this);
var tabName = $btn.data('tab');
jQuery('.cx-v2-tab-btn').removeClass('compressx-v2-border-b-2 compressx-v2-border-blue-600 compressx-v2-font-medium').addClass('compressx-v2-text-slate-600');
$btn.removeClass('compressx-v2-text-slate-600').addClass('compressx-v2-border-blue-600 compressx-v2-font-medium compressx-v2-border-b-2');
jQuery('[data-tab-panel]').addClass('compressx-v2-hidden');
jQuery('[data-tab-panel="' + tabName + '"]').removeClass('compressx-v2-hidden');
});
function updateAutoOptimizeSwitch()
{
var $switchBtn = jQuery('#cx_enable_auto_optimize');
var $knob = $switchBtn.find('span');
var currentState = $switchBtn.attr('data-checked');
var newState = currentState === '1' ? '0' : '1';
$switchBtn.attr('data-checked', newState);
update_switch($switchBtn,$knob);
}
jQuery('#cx-v2-avoid-larger').on('click', function()
{
var $switchBtn = jQuery('#cx-v2-avoid-larger');
var $knob = $switchBtn.find('span');
var currentState = $switchBtn.attr('data-checked');
var newState = currentState === '1' ? '0' : '1';
$switchBtn.attr('data-checked', newState);
update_switch($switchBtn,$knob);
});
jQuery('#cx-v2-resize-enable').on('click', function()
{
var $switchBtn = jQuery('#cx-v2-resize-enable');
var $knob = $switchBtn.find('span');
var currentState = $switchBtn.attr('data-checked');
var newState = currentState === '1' ? '0' : '1';
$switchBtn.attr('data-checked', newState);
update_switch($switchBtn,$knob);
});
function update_switch($switchBtn,$knob)
{
var isChecked = $switchBtn.attr('data-checked') === '1';
if (isChecked) {
$switchBtn.removeClass('compressx-v2-bg-gray-300');
$switchBtn.addClass('compressx-v2-bg-blue-600');
$switchBtn.removeClass('compressx-v2-border-gray-300');
$switchBtn.addClass('compressx-v2-border-blue-600');
$knob.css('transform', 'translateX(20px)');
$switchBtn.attr('aria-checked', 'true');
} else {
$switchBtn.addClass('compressx-v2-bg-gray-300');
$switchBtn.removeClass('compressx-v2-bg-blue-600');
$switchBtn.addClass('compressx-v2-border-gray-300');
$switchBtn.removeClass('compressx-v2-border-blue-600');
$knob.css('transform', 'translateX(0px)');
$switchBtn.attr('aria-checked', 'false');
}
}
jQuery(document).ready(function ($) {
var $switchBtn = jQuery('#cx_enable_auto_optimize');
var $knob = $switchBtn.find('span');
update_switch($switchBtn,$knob);
$switchBtn = jQuery('#cx-v2-avoid-larger');
$knob = $switchBtn.find('span');
update_switch($switchBtn,$knob);
$switchBtn = jQuery('#cx-v2-resize-enable');
$knob = $switchBtn.find('span');
update_switch($switchBtn,$knob);
});
@@ -0,0 +1,345 @@
jQuery('#cx_log_list').on("click",'#cx_log_search_by_date',function()
{
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
compressx_get_logs_list(start_date,start_time,end_date,end_time);
});
jQuery('#cx_log_list').on("click",'.first-page',function() {
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
compressx_get_logs_list(start_date,start_time,end_date,end_time,'first');
});
jQuery('#cx_log_list').on("click",'.prev-page',function() {
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
var page=parseInt(jQuery(this).attr('value'));
compressx_get_logs_list(start_date,start_time,end_date,end_time,page-1);
});
jQuery('#cx_log_list').on("click",'.next-page',function() {
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
var page=parseInt(jQuery(this).attr('value'));
compressx_get_logs_list(start_date,start_time,end_date,end_time,page+1);
});
jQuery('#cx_log_list').on("click",'.last-page',function() {
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
compressx_get_logs_list(start_date,start_time,end_date,end_time,'last');
});
jQuery('#cx_log_list').on("keypress", '.current-page', function() {
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
if(event.keyCode === 13){
var page = jQuery(this).val();
compressx_get_logs_list(start_date,start_time,end_date,end_time,page);
}
});
var currentLogFilename="";
function compressx_get_logs_list(start_date,start_time,end_date,end_time,page=0)
{
var ajax_data = {
'action':'compressx_get_logs_list',
'start_date':start_date,
'start_time':start_time,
'end_date':end_date,
'end_time':end_time,
'page':page
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === "success")
{
jQuery('#cx_log_list').html(jsonarray.html);
jQuery('#cx_log_list').find('#cx_log_start_date').val(start_date);
jQuery('#cx_log_list').find('#cx_log_start_time').val(start_time);
jQuery('#cx_log_list').find('#cx_log_end_date').val(end_date);
jQuery('#cx_log_list').find('#cx_log_end_time').val(end_time);
}
else
{
alert(jsonarray.error);
}
}
catch(err)
{
alert(err);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
var error_message =compressx_output_ajaxerror('get logs list', textStatus, errorThrown);
alert(error_message);
});
}
jQuery('#cx_close_log').click(function()
{
jQuery('#cx_log_detail_section').hide();
});
jQuery('#cx_log_list').on("click",'.cs-log-detail',function()
{
var file_name = jQuery(this).closest('td').data('id');
compressx_open_log(file_name);
});
function compressx_open_log(file_name)
{
var ajax_data = {
'action':'compressx_open_log',
'filename':file_name
};
jQuery('#cx_log_name').html(file_name);
jQuery('#cx_read_optimize_log_content').html("");
jQuery('#cx_log_detail_section').show();
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === "success")
{
currentLogFilename = file_name;
jQuery('#cx_read_optimize_log_content').val(jsonarray.data);
jQuery('#cx_log_created_date').text(jsonarray.create || '--');
jQuery('#cx_log_detail_section').show();
jQuery('html, body').animate({
scrollTop: jQuery('#cx_log_detail_section').offset().top - 100
}, 500);
//jQuery('#cx_read_optimize_log_content').html(jsonarray.html);
//jQuery('html, body').animate({scrollTop: jQuery("#cx_log_scroll_test").offset().top}, 'slow');
}
else
{
jQuery('#cx_read_optimize_log_content').html(jsonarray.error);
}
}
catch(err)
{
alert(err);
var div = "Reading the log failed. Please try again.";
jQuery('#cx_read_optimize_log_content').html(div);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
var error_message =compressx_output_ajaxerror('open log', textStatus, errorThrown);
alert(error_message);
});
}
jQuery('#cx_close_log').on('click', function() {
jQuery('#cx_log_detail_section').hide();
currentLogFilename = '';
});
jQuery('#cx_download_current_log').on('click', function() {
if (!currentLogFilename) {
alert('No log file is currently open');
return;
}
compressx_download_log(currentLogFilename)
});
function compressx_download_log(file_name)
{
location.href =ajaxurl+'?_wpnonce='+compressx_ajax_object.ajax_nonce+'&action=compressx_download_log&log='+file_name;
}
jQuery('#cx_log_list').on("click",'.cs-log-download',function()
{
var file_name = jQuery(this).closest('td').data('id');
compressx_download_log(file_name);
});
jQuery('#cx_log_list').on("click",'.cs-log-delete',function()
{
var file_name = jQuery(this).closest('td').data('id');
var descript = 'Are you sure to delete this log file?';
var ret = confirm(descript);
if(ret === true)
{
compressx_delete_log(file_name);
}
});
function compressx_delete_log(file_name)
{
var ajax_data = {
'action':'compressx_delete_log',
'filename':file_name
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === "success")
{
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
compressx_get_logs_list(start_date,start_time,end_date,end_time);
}
else
{
alert(jsonarray.error);
}
}
catch(err)
{
alert(err);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
var error_message =compressx_output_ajaxerror('delete log', textStatus, errorThrown);
alert(error_message);
});
}
jQuery('#cx_empty_log').click(function()
{
var descript = 'Are you sure to delete All log file?';
var ret = confirm(descript);
if(ret === true)
{
compressx_delete_all_log();
}
});
function compressx_delete_all_log()
{
var ajax_data = {
'action':'compressx_delete_all_log',
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === "success")
{
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
compressx_get_logs_list(start_date,start_time,end_date,end_time);
}
else
{
alert(jsonarray.error);
}
}
catch(err)
{
alert(err);
}
}, function(XMLHttpRequest, textStatus, errorThrown)
{
var error_message =compressx_output_ajaxerror('delete log', textStatus, errorThrown);
alert(error_message);
});
}
jQuery(document).ready(function($) {
$('#compressx_show_debug_form').on('click', function() {
$('#compressx_debug_form_section').show();
$('html, body').animate({
scrollTop: $('#compressx_debug_form_section').offset().top - 100
}, 500);
});
$('#compressx_debug_submit').on('click', function() {
var user_mail = $('#compressx_user_mail').val().trim();
var comment = $('#compressx_debug_comment').val().trim();
if (!user_mail) {
alert("Please enter your email address.");
$('#compressx_user_mail').focus();
return;
}
var $button = $(this);
var originalText = $button.text();
$button.text("Sending...").prop('disabled', true);
var ajax_data = {
action: 'compressx_send_debug_info',
user_mail: user_mail,
comment: comment,
};
compressx_post_request(ajax_data, function(data) {
try {
var response = jQuery.parseJSON(data);
if (response && response.result === 'success') {
alert("Debug information sent successfully!");
$('#compressx_debug_form_section').hide();
$('#compressx_user_mail').val('');
$('#compressx_debug_comment').val('');
} else {
alert(response.error || "Failed to send debug information.");
}
} catch(err) {
alert("Failed to send debug information.");
}
$button.text(originalText).prop('disabled', false);
}, function(XMLHttpRequest, textStatus, errorThrown) {
alert("Failed to send debug information.");
$button.text(originalText).prop('disabled', false);
});
});
$('#compressx_download_debug_info').on('click', function()
{
cx_download_website_info();
});
function cx_download_website_info()
{
location.href =ajaxurl+'?_wpnonce='+compressx_ajax_object.ajax_nonce+'&action=compressx_create_debug_package';
}
});
@@ -0,0 +1,444 @@
jQuery('#cx_replace_media').click(function(e)
{
e.preventDefault();
var input = document.getElementById('compressx-new-media-file');
var file = input && input.files && input.files[0];
if (!file)
{
alert('Please select an image that you want to replace.');
return;
}
var $saveButton = jQuery(this);
$saveButton.css({ 'pointer-events': 'none', 'opacity': '0.4' });
jQuery('#cx_replace_media_progress').show();
let attachment_id=jQuery('#compressx_attachment_id').val();
var ajax_data = {
'action': 'compressx_replace_media',
'attachment_id': attachment_id,
};
compressx_file_upload_request(
ajax_data,
'compressx-new-media-file', //file input id
'image', //$_FILES['image']
function(data)
{
try
{
var jsonarray = JSON.parse(data);
if (jsonarray.result === 'success')
{
//$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx_replace_media_progress').hide();
jQuery('#cx_replace_media_text').removeClass('compressx-v2-hidden');
setTimeout(function() {
jQuery('#cx_replace_media_text').addClass('compressx-v2-hidden');
location.href=compressx_media_replace.redirect_url;
}, 3000);
}
else
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx_replace_media_progress').hide();
alert(jsonarray.error || 'Failed to save settings.');
}
}
catch (err)
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx_replace_media_progress').hide();
alert(err);
}
},
function(XMLHttpRequest, textStatus, errorThrown)
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx_replace_media_progress').hide();
var error_message = compressx_output_ajaxerror('saving settings', textStatus, errorThrown);
alert(error_message);
},
30000
);
});
function compressx_file_upload_request(ajax_data, file_input_id, file_field_name, callback, error_callback, time_out)
{
if (typeof time_out === 'undefined') time_out = 30000;
if (typeof file_field_name === 'undefined' || !file_field_name) file_field_name = 'image';
var form_data = (ajax_data instanceof FormData) ? ajax_data : new FormData();
if (!(ajax_data instanceof FormData)) {
for (var key in ajax_data) {
if (!ajax_data.hasOwnProperty(key)) continue;
form_data.append(key, ajax_data[key]);
}
}
form_data.append('nonce', compressx_ajax_object.ajax_nonce);
var input = document.getElementById(file_input_id);
var file = input && input.files && input.files[0];
if (!file) {
if (typeof error_callback === 'function') {
error_callback(null, 'no_file', 'No file selected.');
}
return;
}
form_data.append(file_field_name, file);
jQuery.ajax({
type: "post",
url: compressx_ajax_object.ajax_url,
data: form_data,
processData: false,
contentType: false,
success: function (data) {
callback(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
error_callback(XMLHttpRequest, textStatus, errorThrown);
},
timeout: time_out
});
}
jQuery(function ($)
{
// ===== Helpers =====
function cx_getSettingsPayload()
{
const auto_re_optimize = $('#cx_auto_re_optimize').is(':checked') ? 1 : 0;
const thumbnail_generation = $('input[name="thumbnail_strategy"]:checked').val() || 'default_fill';
return {
auto_re_optimize,
thumbnail_generation,
};
}
let ajaxTimer = null;
function compressx_save_media_replace_setting(triggerEl,triggerNotice)
{
window.clearTimeout(ajaxTimer);
ajaxTimer = window.setTimeout(function ()
{
const payload = cx_getSettingsPayload();
var ajax_data = {
'action': 'compressx_save_media_replace_setting',
'settings': payload,
};
jQuery(triggerEl).css({'pointer-events': 'none', 'opacity': '0.4'});
compressx_post_request(ajax_data, function (data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
jQuery(triggerEl).css({'pointer-events': 'auto', 'opacity': '1'});
if (jsonarray.result === 'success')
{
jQuery(triggerNotice).removeClass("hidden");
setTimeout(function ()
{
jQuery(triggerNotice).addClass( 'hidden' );
}, 3000);
}
}
catch (err)
{
alert(err);
jQuery(triggerEl).css({'pointer-events': 'auto', 'opacity': '1'});
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
jQuery('triggerEl').css({'pointer-events': 'auto', 'opacity': '1'});
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
alert(error_message);
});
}, 200);
}
// ===== Bindings =====
// checkbox change
$(document).on('change', '#cx_auto_re_optimize', function ()
{
var notice= jQuery("#auto_re_optimize-saved-indicator");
compressx_save_media_replace_setting(this,notice);
});
$(document).on('change', '#cx_backup_original', function ()
{
var notice= jQuery("#cx_backup_original-saved-indicator");
compressx_save_media_replace_setting(this,notice);
});
// radio change
$(document).on('change', 'input[name="thumbnail_strategy"]', function ()
{
var thumbnail_generation = $('input[name="thumbnail_strategy"]:checked').val() || 'default_fill';
var notice=null;
if(thumbnail_generation==='default_fill')
{
notice= jQuery("#default_fill-saved-indicator");
}
else
{
notice= jQuery("#match_original-saved-indicator");
}
compressx_save_media_replace_setting(this,notice);
});
//cx_backup_keep_versions
$(document).on('change', '#cx_backup_keep_versions', function ()
{
var notice= jQuery("#cx_backup_keep_versions-saved-indicator");
compressx_save_media_replace_setting(this,notice);
});
$(document).on('change', '#cx_backup_keep_date', function ()
{
var notice= jQuery("#cx_backup_keep_date-saved-indicator");
compressx_save_media_replace_setting(this,notice);
});
});
jQuery(function ($)
{
var og_type= compressx_media_replace.type;
var $dz = $("#compressx-new-media-dropzone");
var $inp = $("#compressx-new-media-file");
var $lay = $("#compressx-new-media-preview-layout");
var $pclk = $("#compressx-new-media-preview-click");
var $pre = $("#compressx-new-media-preview");
var $remove = $("#compressx-remove-new-media-preview");
var $dim = $("#compressx-new-media-dim");
var $size = $("#compressx-new-media-size");
var $fmt = $("#compressx-new-media-format");
var lastUrl = null;
function humanSize(bytes) {
if (bytes === undefined || bytes === null) return "—";
var units = ["B", "KB", "MB", "GB"], i = 0, n = bytes;
while (n >= 1024 && i < units.length - 1) { n /= 1024; i++; }
var fixed = i === 0 ? 0 : (n >= 10 ? 0 : 1);
return n.toFixed(fixed) + " " + units[i];
}
function getFormat(file) {
if (file.type) {
var p = file.type.split("/");
return (p[1] || "—").toUpperCase();
}
var m = (file.name || "").match(/\.([a-z0-9]+)$/i);
return m ? m[1].toUpperCase() : "—";
}
function showEmpty() {
$lay.hide();
$dz.show();
}
function showFilled() {
$dz.hide();
$lay.show();
}
function setFile(file) {
if (!file) return;
if (!file.type || file.type.indexOf("image/") !== 0) {
alert("Please choose an image file.");
return;
}
try
{
var dt = new DataTransfer();
dt.items.add(file);
$inp[0].files = dt.files;
} catch (e) {}
$size.text(humanSize(file.size));
$fmt.text(getFormat(file));
var url = URL.createObjectURL(file);
var img = new Image();
img.onload = function ()
{
$dim.text(img.naturalWidth + " × " + img.naturalHeight);
if (lastUrl) URL.revokeObjectURL(lastUrl);
lastUrl = url;
$pre.attr("src", url);
cx_showNotice(img.naturalWidth,img.naturalHeight,file.type);
};
img.onerror = function ()
{
URL.revokeObjectURL(url);
alert("Failed to read the image.");
$inp.val("");
$dim.text("—"); $size.text("—"); $fmt.text("—");
$pre.attr("src", "");
showEmpty();
};
img.src = url;
}
function openDialog() {
$inp[0].click();
}
function removeImage()
{
$inp.val("");
$pre.attr("src", "");
$dim.text("—");
$size.text("—");
$fmt.text("—");
if (lastUrl) {
URL.revokeObjectURL(lastUrl);
lastUrl = null;
}
$lay.hide();
$dz.show();
}
$dz.on("click", openDialog);
$pclk.on("click", openDialog);
$remove.on("click", removeImage);
$inp.on("change", function () {
var file = this.files && this.files[0];
if (file) setFile(file);
});
$dz.on("dragenter dragover", function (e) {
e.preventDefault(); e.stopPropagation();
$dz.addClass("compressx-drop-active");
});
$dz.on("dragleave drop", function (e) {
e.preventDefault(); e.stopPropagation();
$dz.removeClass("compressx-drop-active");
});
$dz.on("drop", function (e) {
var files = e.originalEvent && e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files;
var file = files && files[0];
if (file) setFile(file);
});
showEmpty();
function cx_showNotice(width,height,mimetype)
{
let og_w=$("#og_image_dimensions").data("width");
let og_h=$("#og_image_dimensions").data("height");
let og_mime=$("#og_image_dimensions").data("mime");
if(mimetype!==og_mime)
{
$("#cx-upload-notice").show();
$("#cx_notice_title").html("File format must match");
$("#cx_notice_content").html("The replacement file must use the same format as the current media ("+og_mime+" → "+mimetype+" detected). Please upload a "+og_type+" file to avoid unexpected issues.");
removeImage();
return;
}
showFilled();
/*
if(og_w>width)
{
$("#cx-upload-notice").show();
$("#cx_notice_title").html("Smaller Image Detected");
$("#cx_notice_content").html("The replacement image is smaller than the original. Some larger thumbnail sizes may not be generated, which can affect pages that reference those sizes.");
}
else if(og_w<width)
{
$("#cx-upload-notice").show();
$("#cx_notice_title").html("Larger Image Detected");
$("#cx_notice_content").html("The replacement image is significantly larger than the original. This may generate larger thumbnails and increase disk usage.");
}*/
}
$("#cx-hide-upload-notice").on("click", function ()
{
$("#cx-upload-notice").hide();
});
});
jQuery(document).ready(function ($)
{
$(document).on('click', '.cx-restore-btn', function ()
{
var $btn = $(this);
var backup_id = $btn.data('backup-id');
var attachment_id = $btn.data('attachment-id');
var ajax_data = {
'action': 'compressx_restore_media_replace',
'backup_id': backup_id,
'attachment_id':attachment_id
};
jQuery(".cx-restore-btn").css({'pointer-events': 'none', 'opacity': '0.4'});
var $wrap = $btn.closest('.cx-restore-item');
let $progress = $wrap.find('.cx-restore-progress');
let $success = $wrap.find('.cx-restore-text');
$progress.show();
compressx_post_request(ajax_data, function (data)
{
jQuery(".cx-restore-btn").css({'pointer-events': 'auto', 'opacity': '1'});
$progress.hide();
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
$success.removeClass("hidden");
setTimeout(function ()
{
location.href=compressx_media_replace.redirect_url;
$success.addClass('hidden');
}, 3000);
}
}
catch (err)
{
alert(err);
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
jQuery(".cx-restore-btn").css({'pointer-events': 'auto', 'opacity': '1'});
var error_message = compressx_output_ajaxerror('replace media', textStatus, errorThrown);
alert(error_message);
});
});
});
@@ -0,0 +1,326 @@
function compressx_init_exclude_tree()
{
jQuery('#compressx_exclude_js_tree').on('activate_node.jstree', function (event, data) {
}).jstree({
"core": {
"check_callback": true,
"multiple": true,
"data": function (node_id, callback) {
var tree_node = {
'node': node_id,
'path': compressx_uploads_root.path
};
var ajax_data = {
'action': 'compressx_get_custom_tree_dir',
'tree_node': tree_node,
};
ajax_data.nonce=compressx_ajax_object.ajax_nonce;
jQuery.ajax({
type: "post",
url: compressx_ajax_object.ajax_url,
data: ajax_data,
success: function (data) {
var jsonarray = jQuery.parseJSON(data);
callback.call(this, jsonarray.nodes);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//alert("error");
},
timeout: 30000
});
},
'themes': {
'stripes': true
}
},
"plugins": ["sort"],
"sort": function(a, b) {
a1 = this.get_node(a);
b1 = this.get_node(b);
if (a1.icon === b1.icon) {
return (a1.text.toLowerCase() > b1.text.toLowerCase()) ? 1 : -1;
} else {
return (a1.icon > b1.icon) ? 1 : -1;
}
},
});
}
jQuery(document).ready(function ()
{
compressx_init_exclude_tree();
jQuery('#cx-v2-show-more-size').click(function() {
jQuery('.cx-v2-thumbnail-size').show();
jQuery(this).hide();
});
jQuery('#cx-v2-save-settings').click(function(e)
{
e.preventDefault();
var $saveButton = jQuery(this);
var originalText = $saveButton.text();
$saveButton.css({ 'pointer-events': 'none', 'opacity': '0.4' });
jQuery('#cx-v2-save-settings-progress').show();
var settings = {
size_settings: {},
list_view_setting: {},
cache_control_setting: {},
scan_page_setting:{},
};
jQuery('input[option="size_setting"]').each(function() {
var name = jQuery(this).attr('name');
var checked = jQuery(this).is(':checked');
settings.size_settings[name] = checked;
});
jQuery('input[option="list_view_setting"]').each(function() {
var name = jQuery(this).attr('name');
var checked = jQuery(this).is(':checked');
settings.list_view_setting[name] = checked ? '1' : '0';
});
jQuery('input[option="cache_control_setting"]').each(function() {
var name = jQuery(this).attr('name');
var checked = jQuery(this).is(':checked');
settings.cache_control_setting[name] = checked ? '1' : '0';
});
jQuery('input[option="scan_page_setting"]').each(function() {
var name = jQuery(this).attr('name');
var value = parseInt(jQuery(this).val(), 10);
if (isNaN(value) || value <= 0) {
value = 500;
}
settings.scan_page_setting[name] = value;
});
var select_folders = jQuery('#compressx_exclude_dir_node').find('.cx-remove-custom-exclude-tree');
var json = {};
jQuery.each(select_folders, function ()
{
var value=jQuery(this).data("id");
//var value = select_item.data( 'id' );
json[value]=value;
});
var exclude_node=JSON.stringify(json);
//
var ajax_data = {
'action': 'compressx_v2_save_settings',
'settings': JSON.stringify(settings),
'excludes':exclude_node,
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = JSON.parse(data);
if (jsonarray.result === 'success')
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
jQuery('#cx-v2-save-settings-text').removeClass('hidden');
setTimeout(function() {
jQuery('#cx-v2-save-settings-text').addClass('hidden');
}, 3000);
}
else
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
alert(jsonarray.error || 'Failed to save settings.');
}
}
catch (err)
{
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
alert('An error occurred while saving settings.');
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
$saveButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-save-settings-progress').hide();
var error_message = compressx_output_ajaxerror('saving settings', textStatus, errorThrown);
alert(error_message);
});
});
});
jQuery('#compressx_exclude_js_tree').on('click', '.cx-add-custom-exclude-tree', function()
{
var id=jQuery(this).data("id");
var node=jQuery(this).parent();
var select_folders = jQuery('#compressx_exclude_dir_node').find('.cx-remove-custom-exclude-tree');
var json = {};
var bfind=false;
jQuery.each(select_folders, function ()
{
var value=jQuery(this).data("id");
if(value==id)
{
bfind=true;
}
});
if(bfind)
return;
var ajax_data = {
'action': 'compressx_add_exclude_folder',
'id': id,
};
compressx_post_request(ajax_data, function (data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
if (jsonarray.result === 'success')
{
jQuery('#compressx_exclude_dir_node').find('ul:first').append(jsonarray.html);
}
else {
alert(jsonarray.error);
}
}
catch (err)
{
alert(err);
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'auto', 'opacity': '1'});
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'auto', 'opacity': '1'});
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
alert(error_message);
});
});
jQuery('#compressx_exclude_dir_node').on('click', '.cx-remove-custom-exclude-tree', function()
{
var id=jQuery(this).data("id");
var node=jQuery(this).parent();
node.remove();
});
function compressx_add_exclude_folders()
{
var select_folders = jQuery('#compressx_exclude_dir_node').find('.cx-remove-custom-exclude-tree');
var json = {};
jQuery.each(select_folders, function ()
{
var value=jQuery(this).data("id");
//var value = select_item.data( 'id' );
json[value]=value;
});
var exclude_node=JSON.stringify(json);
var ajax_data = {
'action': 'compressx_add_exclude_folders',
'excludes': exclude_node,
};
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'none', 'opacity': '0.4'});
jQuery('#compressx_save_exclude_progress').show();
compressx_post_request(ajax_data, function (data)
{
try
{
var jsonarray = jQuery.parseJSON(data);
jQuery('#compressx_save_exclude_progress').hide();
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'auto', 'opacity': '1'});
if (jsonarray.result === 'success')
{
jQuery('#compressx_save_exclude_text').removeClass("hidden");
setTimeout(function ()
{
jQuery('#compressx_save_exclude_text').addClass( 'hidden' );
}, 3000);
jQuery('#compressx_exclude_dir_node').html(jsonarray.html);
}
else {
alert(jsonarray.error);
}
}
catch (err)
{
alert(err);
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#compressx_save_exclude_progress').hide();
}
}, function (XMLHttpRequest, textStatus, errorThrown)
{
jQuery('#compressx_add_exclude_folders').css({'pointer-events': 'auto', 'opacity': '1'});
jQuery('#compressx_add_exclude_folders').hide();
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
alert(error_message);
});
}
jQuery('#cx-v2-delete-file').click(function() {
var confirm_text = jQuery('#cx-v2-confirm-delete-file').val();
if (confirm_text !== 'DELETE') {
alert('Please type "DELETE" to confirm.');
return;
}
if (!confirm('Are you sure you want to delete all WebP and AVIF images? This action cannot be undone.')) {
return;
}
var $deleteButton = jQuery(this);
$deleteButton.css({ 'pointer-events': 'none', 'opacity': '0.4' });
jQuery('#cx-v2-delete-file-progress').show();
var ajax_data = {
'action': 'compressx_delete_files'
};
compressx_post_request(ajax_data, function(data)
{
try
{
var jsonarray = JSON.parse(data);
if (jsonarray.result === 'success')
{
$deleteButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-delete-file-progress').hide();
jQuery('#cx-v2-delete-file-success').removeClass('hidden');
jQuery('#cx-v2-confirm-delete-file').val('');
setTimeout(function() {
jQuery('#cx-v2-delete-file-success').addClass('hidden');
}, 3000);
} else {
$deleteButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-delete-file-progress').hide();
alert(jsonarray.error || 'Failed to delete files.');
}
} catch (err) {
$deleteButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-delete-file-progress').hide();
alert('An error occurred while deleting files.');
}
}, function(XMLHttpRequest, textStatus, errorThrown) {
$deleteButton.css({ 'pointer-events': 'auto', 'opacity': '1' });
jQuery('#cx-v2-delete-file-progress').hide();
var error_message = compressx_output_ajaxerror('deleting files', textStatus, errorThrown);
alert(error_message);
});
});