PluginProbe
Imsanity / 2.5.0
Imsanity v2.5.0
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 2.5.0, at scripts/imsanity.js

124 lines 3.8 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 /**
8 * Begin the process of re-sizing all of the checked images
9 */
10 function imsanity_resize_images()
11 {
12 var images = [];
13 jQuery('.imsanity_image_cb:checked').each(function(i) {
14 images.push(this.value);
15 });
16
17 var target = jQuery('#resize_results');
18 target.html('');
19 //jQuery(document).scrollTop(target.offset().top);
20
21 // start the recursion
22 imsanity_resize_next(images,0);
23 }
24
25 /**
26 * recursive function for resizing images
27 */
28 function imsanity_resize_next(images,next_index)
29 {
30 if (next_index >= images.length) return imsanity_resize_complete();
31
32 jQuery.post(
33 ajaxurl, // (defined by wordpress - points to admin-ajax.php)
34 {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_resize_image', id: images[next_index]},
35 function(response)
36 {
37 var result;
38 var target = jQuery('#resize_results');
39 target.show();
40
41 try {
42 result = JSON.parse(response);
43 target.append('<div>' + (next_index+1) + '/' + images.length + ' &gt;&gt; ' + result['message'] +'</div>');
44 }
45 catch(e) {
46 target.append('<div>' + imsanity_vars.invalid_response + '</div>');
47 if (console) {
48 console.warn(images[next_index] + ': '+ e.message);
49 console.warn('Invalid JSON Response: ' + response);
50 }
51 }
52
53 target.animate({scrollTop: target.prop('scrollHeight')}, 200);
54 // recurse
55 imsanity_resize_next(images,next_index+1);
56 }
57 );
58 }
59
60 /**
61 * fired when all images have been resized
62 */
63 function imsanity_resize_complete()
64 {
65 var target = jQuery('#resize_results');
66 target.append('<div><strong>' + imsanity_vars.resizing_complete + '</strong></div>');
67 target.animate({scrollTop: target.prop('scrollHeight')});
68 }
69
70 /**
71 * ajax post to return all images that are candidates for resizing
72 * @param string the id of the html element into which results will be appended
73 */
74 function imsanity_load_images(container_id)
75 {
76 var container = jQuery('#'+container_id);
77
78 var target = jQuery('#imsanity_target');
79 target.show();
80 jQuery('.imsanity-selection').remove();
81 jQuery('#imsanity_loading').show();
82
83 target.animate({height: [250,'swing']},500, function()
84 {
85 jQuery(document).scrollTop(container.offset().top);
86
87 jQuery.post(
88 ajaxurl, // (global defined by wordpress - points to admin-ajax.php)
89 {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_get_images'},
90 function(response) {
91 var is_json = true;
92 try {
93 var images = jQuery.parseJSON(response);
94 } catch ( err ) {
95 is_json = false;
96 }
97 if ( ! is_json ) {
98 console.log( response );
99 return false;
100 }
101
102 jQuery('#imsanity_loading').hide();
103 if (images.length > 0)
104 {
105 target.append('<div class="imsanity-selection"><input id="imsanity_check_all" type="checkbox" checked="checked" onclick="jQuery(\'.imsanity_image_cb\').attr(\'checked\', this.checked);" /> Select All</div>');
106 for (var i = 0; i < images.length; i++)
107 {
108 target.append('<div class="imsanity-selection"><input class="imsanity_image_cb" name="imsanity_images" value="' + images[i].id + '" type="checkbox" checked="checked" />' + imsanity_vars.image + ' ' + images[i].id + ': ' + images[i].file +' ('+images[i].width+' x '+images[i].height+')</div>');
109 }
110 if ( ! jQuery( '#resize-submit' ).length ) {
111 container.append('<p id="resize-submit" class="submit"><button class="button-primary" onclick="imsanity_resize_images();">' + imsanity_vars.resize_selected + '</button></p>');
112 container.append('<div id="resize_results" style="display: none; border: solid 2px #666666; padding: 10px; height: 250px; overflow: auto;" />');
113 }
114 }
115 else
116 {
117 target.html('<div>' + imsanity_vars.none_found + '</div>');
118
119 }
120 }
121 );
122 });
123 }
124