PluginProbe
Imsanity / trunk
Imsanity vtrunk
2.9.4 2.9.3 2.9.2 trunk 2.4.3 2.5.0 2.6.0 2.7.0 2.7.2 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1
imsanity / scripts / imsanity.js

imsanity.js in Imsanity trunk, at scripts/imsanity.js

158 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * imsanity admin javascript functions
3 */
4
5 jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);});
6
7 // Handle a manual resize from the media library.
8 jQuery(document).on('click', '.imsanity-manual-resize', function() {
9 var post_id = jQuery(this).data('id');
10 var imsanity_nonce = jQuery(this).data('nonce');
11 jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing );
12 jQuery.post(
13 ajaxurl,
14 {_wpnonce: imsanity_nonce, action: 'imsanity_resize_image', id: post_id},
15 function(response) {
16 var target = jQuery('#imsanity-media-status-' + post_id );
17 try {
18 target.html(response.message);
19 } catch(e) {
20 target.html(imsanity_vars.invalid_response);
21 if (console) {
22 console.warn(post_id + ': '+ e.message);
23 console.warn('Invalid JSON Response: ' + JSON.stringify(response));
24 }
25 }
26 }
27 );
28 return false;
29 });
30
31 // Handle an original image removal request from the media library.
32 jQuery(document).on('click', '.imsanity-manual-remove-original', function() {
33 var post_id = jQuery(this).data('id');
34 var imsanity_nonce = jQuery(this).data('nonce');
35 jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing );
36 jQuery.post(
37 ajaxurl,
38 {_wpnonce: imsanity_nonce, action: 'imsanity_remove_original', id: post_id},
39 function(response) {
40 var target = jQuery('#imsanity-media-status-' + post_id );
41 try {
42 if (! response.success) {
43 target.html(imsanity_vars.removal_failed);
44 } else {
45 target.html(imsanity_vars.removal_succeeded);
46 }
47 } catch(e) {
48 target.html(imsanity_vars.invalid_response);
49 if (console) {
50 console.warn(post_id + ': '+ e.message);
51 console.warn('Invalid JSON Response: ' + JSON.stringify(response));
52 }
53 }
54 }
55 );
56 return false;
57 });
58
59 jQuery(document).on('submit', '#imsanity-bulk-stop', function() {
60 jQuery(this).hide();
61 imsanity_vars.stopped = true;
62 imsanity_vars.attachments = [];
63 jQuery('#imsanity_loading').html(imsanity_vars.operation_stopped);
64 jQuery('#imsanity_loading').show();
65 return false;
66 });
67
68 /**
69 * Begin the process of re-sizing all of the checked images
70 */
71 function imsanity_resize_images() {
72 // start the recursion
73 imsanity_resize_next(0);
74 }
75
76 /**
77 * recursive function for resizing images
78 */
79 function imsanity_resize_next(next_index) {
80 if (next_index >= imsanity_vars.attachments.length) return imsanity_resize_complete();
81 var total_images = imsanity_vars.attachments.length;
82 var target = jQuery('#resize_results');
83 target.show();
84
85 jQuery.post(
86 ajaxurl, // (defined by wordpress - points to admin-ajax.php)
87 {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_resize_image', id: imsanity_vars.attachments[next_index], resumable: 1},
88 function (response) {
89 var result;
90 jQuery('#bulk-resize-beginning').hide();
91
92 try {
93 target.append('<div>' + (next_index+1) + '/' + total_images + ' &gt;&gt; ' + response.message +'</div>');
94 } catch(e) {
95 target.append('<div>' + imsanity_vars.invalid_response + '</div>');
96 if (console) {
97 console.warn(imsanity_vars.attachments[next_index] + ': '+ e.message);
98 console.warn('Invalid JSON Response: ' + JSON.stringify(response));
99 }
100 }
101 // recurse
102 imsanity_resize_next(next_index+1);
103 }
104 );
105 }
106
107 /**
108 * fired when all images have been resized
109 */
110 function imsanity_resize_complete() {
111 var target = jQuery('#resize_results');
112 if (! imsanity_vars.stopped) {
113 jQuery('#imsanity-bulk-stop').hide();
114 target.append('<div><strong>' + imsanity_vars.resizing_complete + '</strong></div>');
115 jQuery.post(
116 ajaxurl, // (global defined by wordpress - points to admin-ajax.php)
117 {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_bulk_complete'}
118 );
119 }
120 }
121
122 /**
123 * ajax post to return all images from the library
124 * @param string the id of the html element into which results will be appended
125 */
126 function imsanity_load_images() {
127 var imsanity_really_resize_all = confirm(imsanity_vars.resize_all_prompt);
128 if ( ! imsanity_really_resize_all ) {
129 return;
130 }
131 jQuery('#imsanity-examine-button').hide();
132 jQuery('.imsanity-bulk-text').hide();
133 jQuery('#imsanity-bulk-reset').hide();
134 jQuery('#imsanity_loading').show();
135
136 jQuery.post(
137 ajaxurl, // (global defined by wordpress - points to admin-ajax.php)
138 {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_get_images', resume_id: imsanity_vars.resume_id},
139 function(response) {
140 var images = response;
141 if (! Array.isArray(images)) {
142 console.log( response );
143 return false;
144 }
145
146 jQuery('#imsanity_loading').hide();
147 if (images.length > 0) {
148 imsanity_vars.attachments = images;
149 imsanity_vars.stopped = false;
150 jQuery('#imsanity-bulk-stop').show();
151 imsanity_resize_images();
152 } else {
153 jQuery('#imsanity_loading').html('<div>' + imsanity_vars.none_found + '</div>');
154 }
155 }
156 );
157 }
158