Plugin Directory

Changeset 3338193

Timestamp:
08/02/2025 11:19:55 AM (7 months ago)
Author:
adgardner1392
Message:

refactor: commit version 1.4.1 amend media conversion to use vanilla JS (remove jQuery)

Location:
webp-image-optimization
Files:
11 added
3 edited

Legend:

Unmodified
Added
Removed
  • webp-image-optimization/trunk/README.txt

    r3164543 r3338193  
    66Tested up to: 6.6.2 
    77Requires PHP: 7.2 
    8 Stable tag: 1.4.0
     8Stable tag: 1.4.
    99License: GPLv2 or later 
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    172172== Upgrade Notice ==
    173173
     174
     175
     176
     177
    174178= 1.4.0 =
    175179
  • webp-image-optimization/trunk/js/media.js

    r3164521 r3338193  
    11// js/media.js
    22
    3 jQuery(document).ready(function($) {
     3) {
    44    /**
    55     * Handle "Convert to WebP" button click
    66     */
    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
    811        e.preventDefault();
    912
    10         var button = $(this);
    11         var attachmentId = button.data('attachment-id');
     13        const attachmentId = button.getAttribute('data-attachment-id');
    1214
    1315        if (!attachmentId) {
     
    1618        }
    1719
    18         // Disable the button to prevent multiple clicks and update its text
    19         button.prop('disabled', true);
    20         var originalButtonText = button.text();
    21         button.text('Converting...');
     20        // Disable the button text
     21        button.;
     22        ;
     23        button.text;
    2224
    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);
    2930
    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 => {
    3241            if (response.success) {
    3342                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();
    3644            } else {
    3745                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;
    4148            }
    42         }).fail(function(xhr, status, error) {
     49        })
     50        .catch(error => {
    4351            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;
    4754        });
    4855    });
  • webp-image-optimization/trunk/webp-image-optimization.php

    r3164543 r3338193  
    44Plugin URI: https://github.com/adgardner1392/webp-image-optimization
    55Description: 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.0
     6Version: 1.4.
    77Author: Adam Gardner
    88Author URI: https://github.com/adgardner1392
     
    6464                plugin_dir_url( __FILE__ ) . 'css/admin.css',
    6565                array(),
    66                 '1.3.1'
     66                '1..1'
    6767            );
    6868
     
    7272                plugin_dir_url( __FILE__ ) . 'js/admin.js',
    7373                array( 'jquery' ),
    74                 '1.3.1',
     74                '1..1',
    7575                true
    7676            );
     
    9090                plugin_dir_url( __FILE__ ) . 'js/media.js',
    9191                array( 'jquery' ),
    92                 '1.3.1',
     92                '1..1',
    9393                true
    9494            );
Note: See TracChangeset for help on using the changeset viewer.