-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcws-admin-script.js
More file actions
34 lines (30 loc) · 1.1 KB
/
cws-admin-script.js
File metadata and controls
34 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
jQuery(document).ready(function($) {
// Handle individual media item action
$('a.cws-compare-webp-size').on('click', function(e) {
e.preventDefault();
var attachmentId = $(this).data('id');
var resultDiv = $('#cws-result-' + attachmentId);
// If the result div doesn't exist, create it
if (resultDiv.length === 0) {
resultDiv = $('<div class="cws-result" id="cws-result-' + attachmentId + '"></div>').insertAfter($(this));
} else {
resultDiv.empty(); // Clear previous messages
}
resultDiv.html('<p>Processing...</p>');
$.ajax({
url: ajaxurl,
type: 'GET',
data: {
action: 'cws_compare_webp_size',
attachment_id: attachmentId
},
success: function(response) {
if (response.success) {
resultDiv.html('<p>' + response.data + '</p>');
} else {
resultDiv.html('<p>Error: ' + response.data + '</p>');
}
}
});
});
});