PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / trunk
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization vtrunk
4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 All 135 releases
optimole-wp / assets / js / media.js

media.js in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization trunk, at assets/js/media.js

42 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 jQuery('.move-image-optml').click(function() {
3 //get the id and send a jquery rest request to the server
4 var id = jQuery(this).data('id');
5 var action = jQuery(this).data('action');
6 moveImage(id, action, jQuery(this));
7 });
8 });
9
10 function moveImage(id, action, element, is_retry = false) {
11 //add a loading indicator
12 element.parent().find('.spinner').addClass('is-active');
13 element.parent().addClass('is-loading');
14 jQuery.ajax({
15 url: optimoleMediaListing.rest_url,
16 type: 'POST',
17 headers: {
18 'X-WP-Nonce': optimoleMediaListing.nonce
19 },
20 data: {
21 action: action,
22 status: is_retry ? 'check' : 'start',
23 id: id
24 },
25 success: function(response) {
26 if(response.code === 'moved') {
27 element.parent().find('.spinner').removeClass('is-active');
28 element.parent().removeClass('is-loading');
29 element.parent().find('.move-image-optml').toggleClass('hidden');
30
31 }else if(response.code === 'error'){
32 element.parent().find('.spinner').removeClass('is-active');
33 element.parent().removeClass('is-loading');
34 element.parent().text(response.data);
35 }else{
36 setTimeout(function() {
37 moveImage(id, action, element, true);
38 }, 1000);
39 }
40 }
41 });
42 }