Skip to content

Commit 78160a3

Browse files
authored
Merge pull request #905 from Codeinwp/feat/client-optimizations
Feat/client optimizations
2 parents 2b246ef + 509e734 commit 78160a3

38 files changed

+3119
-559
lines changed

assets/js/media.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

0 commit comments

Comments
 (0)