-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-exif.js
More file actions
50 lines (45 loc) · 2.08 KB
/
quick-exif.js
File metadata and controls
50 lines (45 loc) · 2.08 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Run this code when the page has fully loaded
document.addEventListener('DOMContentLoaded', function () {
// Get references to the button and status message area
const btn = document.getElementById('quick-exif-test-button');
const status = document.getElementById('quick-exif-status');
// Only continue if the button exists on the page
if (btn) {
// Add click event listener to the button
btn.addEventListener('click', function (e) {
e.preventDefault(); // Prevent any default button behavior
// Show loading message
status.textContent = '📷 Extracting EXIF...';
// Send AJAX request to WordPress backend using Fetch API
fetch(QuickExifData.ajaxUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'quick_exif_extract', // WordPress action name
nonce: QuickExifData.nonce, // Security nonce
postId: QuickExifData.postId, // Current post ID
}),
})
// Convert response to JSON
.then(res => res.json())
// Handle response data
.then(data => {
if (data.success) {
// Show success message and reload page after 1 second
status.textContent = '✅ EXIF data saved. Reloading...';
setTimeout(() => location.reload(), 1000);
} else {
// Show error message from server
status.textContent = '❌ Error: ' + data.data;
}
})
// Handle network or other unexpected errors
.catch(err => {
status.textContent = '❌ Request failed.';
console.error(err); // Log details to console for debugging
});
});
}
});