/** * imsanity admin javascript functions */ jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);}); // Handle a manual resize from the media library. jQuery(document).on('click', '.imsanity-manual-resize', function() { var post_id = jQuery(this).data('id'); var imsanity_nonce = jQuery(this).data('nonce'); jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing ); jQuery.post( ajaxurl, {_wpnonce: imsanity_nonce, action: 'imsanity_resize_image', id: post_id}, function(response) { var target = jQuery('#imsanity-media-status-' + post_id ); try { target.html(response.message); } catch(e) { target.html(imsanity_vars.invalid_response); if (console) { console.warn(post_id + ': '+ e.message); console.warn('Invalid JSON Response: ' + JSON.stringify(response)); } } } ); return false; }); // Handle an original image removal request from the media library. jQuery(document).on('click', '.imsanity-manual-remove-original', function() { var post_id = jQuery(this).data('id'); var imsanity_nonce = jQuery(this).data('nonce'); jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing ); jQuery.post( ajaxurl, {_wpnonce: imsanity_nonce, action: 'imsanity_remove_original', id: post_id}, function(response) { var target = jQuery('#imsanity-media-status-' + post_id ); try { if (! response.success) { target.html(imsanity_vars.removal_failed); } else { target.html(imsanity_vars.removal_succeeded); } } catch(e) { target.html(imsanity_vars.invalid_response); if (console) { console.warn(post_id + ': '+ e.message); console.warn('Invalid JSON Response: ' + JSON.stringify(response)); } } } ); return false; }); jQuery(document).on('submit', '#imsanity-bulk-stop', function() { jQuery(this).hide(); imsanity_vars.stopped = true; imsanity_vars.attachments = []; jQuery('#imsanity_loading').html(imsanity_vars.operation_stopped); jQuery('#imsanity_loading').show(); return false; }); /** * Begin the process of re-sizing all of the checked images */ function imsanity_resize_images() { // start the recursion imsanity_resize_next(0); } /** * recursive function for resizing images */ function imsanity_resize_next(next_index) { if (next_index >= imsanity_vars.attachments.length) return imsanity_resize_complete(); var total_images = imsanity_vars.attachments.length; var target = jQuery('#resize_results'); target.show(); jQuery.post( ajaxurl, // (defined by wordpress - points to admin-ajax.php) {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_resize_image', id: imsanity_vars.attachments[next_index], resumable: 1}, function (response) { var result; jQuery('#bulk-resize-beginning').hide(); try { target.append('