Changeset 3338193
- Timestamp:
- 08/02/2025 11:19:55 AM (7 months ago)
- Location:
- webp-image-optimization
- Files:
-
- 11 added
- 3 edited
-
tags/1.4.1 (added)
-
tags/1.4.1/README.txt (added)
-
tags/1.4.1/assets (added)
-
tags/1.4.1/assets/screenshot-1.png (added)
-
tags/1.4.1/assets/screenshot-2.png (added)
-
tags/1.4.1/css (added)
-
tags/1.4.1/css/admin.css (added)
-
tags/1.4.1/js (added)
-
tags/1.4.1/js/admin.js (added)
-
tags/1.4.1/js/media.js (added)
-
tags/1.4.1/webp-image-optimization.php (added)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/js/media.js (modified) (2 diffs)
-
trunk/webp-image-optimization.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
webp-image-optimization/trunk/README.txt
r3164543 r3338193 6 6 Tested up to: 6.6.2 7 7 Requires PHP: 7.2 8 Stable tag: 1.4. 08 Stable tag: 1.4. 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 172 172 == Upgrade Notice == 173 173 174 175 176 177 174 178 = 1.4.0 = 175 179 -
webp-image-optimization/trunk/js/media.js
r3164521 r3338193 1 1 // js/media.js 2 2 3 jQuery(document).ready(function($) {3 ) { 4 4 /** 5 5 * Handle "Convert to WebP" button click 6 6 */ 7 $(document).on('click', '.convert-to-webp', function(e) { 7 document.addEventListener('click', function (e) { 8 const button = e.target.closest('.convert-to-webp'); 9 if (!button) return; 10 8 11 e.preventDefault(); 9 12 10 var button = $(this); 11 var attachmentId = button.data('attachment-id'); 13 const attachmentId = button.getAttribute('data-attachment-id'); 12 14 13 15 if (!attachmentId) { … … 16 18 } 17 19 18 // Disable the button to prevent multiple clicks and update itstext19 button. prop('disabled', true);20 var originalButtonText = button.text();21 button.text ('Converting...');20 // Disable the button text 21 button.; 22 ; 23 button.text; 22 24 23 // Prepare the data to be sent in the POST request 24 var data = { 25 action: 'webp_convert_attachment', 26 nonce: webpImageOptimization.nonce, 27 attachment_id: attachmentId 28 }; 25 // Prepare the data 26 const data = new URLSearchParams(); 27 data.append('action', 'webp_convert_attachment'); 28 data.append('nonce', webpImageOptimization.nonce); 29 data.append('attachment_id', attachmentId); 29 30 30 // Send AJAX POST request using jQuery 31 $.post(webpImageOptimization.ajax_url, data, function(response) { 31 // Send AJAX request using fetch 32 fetch(webpImageOptimization.ajax_url, { 33 method: 'POST', 34 headers: { 35 'Content-Type': 'application/x-www-form-urlencoded', 36 }, 37 body: data.toString() 38 }) 39 .then(response => response.json()) 40 .then(response => { 32 41 if (response.success) { 33 42 alert('Image successfully converted to WebP.'); 34 // Optionally, refresh the page or update the image preview 35 location.reload(); // Refresh to see changes 43 location.reload(); 36 44 } else { 37 45 alert('Conversion failed: ' + response.data); 38 // Re-enable the button in case of failure 39 button.prop('disabled', false); 40 button.text(originalButtonText); 46 button.disabled = false; 47 button.textContent = originalButtonText; 41 48 } 42 }).fail(function(xhr, status, error) { 49 }) 50 .catch(error => { 43 51 alert('An error occurred: ' + error); 44 // Re-enable the button in case of error 45 button.prop('disabled', false); 46 button.text(originalButtonText); 52 button.disabled = false; 53 button.textContent = originalButtonText; 47 54 }); 48 55 }); -
webp-image-optimization/trunk/webp-image-optimization.php
r3164543 r3338193 4 4 Plugin URI: https://github.com/adgardner1392/webp-image-optimization 5 5 Description: Automatically converts uploaded images to WebP format and resizes them. Also allows manual conversion from the Media Library with undo functionality. 6 Version: 1.4. 06 Version: 1.4. 7 7 Author: Adam Gardner 8 8 Author URI: https://github.com/adgardner1392 … … 64 64 plugin_dir_url( __FILE__ ) . 'css/admin.css', 65 65 array(), 66 '1. 3.1'66 '1..1' 67 67 ); 68 68 … … 72 72 plugin_dir_url( __FILE__ ) . 'js/admin.js', 73 73 array( 'jquery' ), 74 '1. 3.1',74 '1..1', 75 75 true 76 76 ); … … 90 90 plugin_dir_url( __FILE__ ) . 'js/media.js', 91 91 array( 'jquery' ), 92 '1. 3.1',92 '1..1', 93 93 true 94 94 );
Note: See TracChangeset
for help on using the changeset viewer.