PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.5
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.5
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / assets / js / upload.js

upload.js in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.5, at assets/js/upload.js

157 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(function($){
2 /*
3 * Add a "Imagify'em all" in the select list
4 */
5 var bulk_opt = '<option value="imagify-bulk-upload">' + imagifyUpload.bulkActionsLabels.optimize + '</option>';
6 bulk_opt += '<option value="imagify-bulk-restore">' + imagifyUpload.bulkActionsLabels.restore + '</option>';
7
8 $('.bulkactions select[name="action"]').find('option:last-child').before( bulk_opt );
9 $('.bulkactions select[name="action2"]').find('option:last-child').before( bulk_opt );
10
11 /*
12 * Process optimization for all selected images
13 */
14 $('#doaction').add('#doaction2')
15 .on('click', function(e) {
16 value = $(this).prev('select').val();
17 value = value.split('-');
18
19 if ( 'imagify' !== value[0] ) {
20 return;
21 }
22
23 e.preventDefault();
24
25 action = value[2];
26 ids = $('input[name^="media"]:checked').map( function(){
27 return this.value;
28 }).get();
29
30 ids.forEach( function( id, index ) {
31 setTimeout(function(){
32 $('#imagify-' + action + '-' + id ).trigger('click');
33 }, index*300);
34 });
35
36 });
37
38 /*
39 * Process to one of these actions: restore, optimize or re-optimize
40 */
41 $(document).on('click', '.button-imagify-restore, .button-imagify-manual-upload, .button-imagify-manual-override-upload', function(e){
42 e.preventDefault();
43
44 var $obj = $(this);
45 var $parent = ( $obj.parents('.column-imagify_optimized_file, .compat-field-imagify .field').length ) ? $obj.parents('.column-imagify_optimized_file, .compat-field-imagify .field') : $obj.closest('.column');
46 var href = $obj.attr('href');
47
48 $parent.html('<div class="button"><span class="imagify-spinner"></span>' + $obj.data('waiting-label') + '</div>');
49
50 $.get( href.replace( 'admin-post.php', 'admin-ajax.php' ) )
51 .done( function( response ){
52 $parent.html( response.data );
53 $parent.find('.imagify-datas-more-action a').addClass('is-open').find('.the-text').text( $parent.find('.imagify-datas-more-action a').data('close') );
54 $parent.find('.imagify-datas-details').addClass('is-open');
55
56 draw_me_a_chart( $parent.find('.imagify-chart-container').find('canvas') );
57 } );
58 } );
59
60 /*
61 * Toggle slide in custom column
62 */
63 $('.imagify-datas-details').hide();
64
65 $(document).on('click', '.imagify-datas-more-action a', function(){
66 if ( $(this).hasClass('is-open') ) {
67 $( $(this).attr('href') ).slideUp('300').removeClass('is-open');
68 $(this).removeClass('is-open').find('.the-text').text( $(this).data('open') );
69 }
70 else {
71 $( $(this).attr('href') ).slideDown('300').addClass('is-open');
72 $(this).addClass('is-open').find('.the-text').text( $(this).data('close') );
73 }
74 return false;
75 });
76
77
78 // Some usefull functions to help us with media modal
79
80 var get_var = function (param) {
81 var vars = {};
82 window.location.href.replace(
83 /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
84 function( m, key, value ) { // callback
85 vars[key] = value !== undefined ? value : '';
86 }
87 );
88
89 if ( param ) {
90 return vars[param] ? vars[param] : null;
91 }
92 return vars;
93 },
94 check_modal = function() {
95 var tempTimer = setInterval( function(){
96 if ( $('.media-modal').find('.imagify-datas-details').length ) {
97 $('.media-modal').find('.imagify-datas-details').hide();
98 draw_me_a_chart( $('.media-modal').find('#imagify-consumption-chart') );
99 clearInterval(tempTimer);
100 tempTimer = null;
101 }
102 }, 20 );
103 };
104
105 // Intercept the right moment if media details is clicked (mode grid)
106 // Bear Feint
107
108 $('.upload-php').find('.media-frame.mode-grid').on('click', '.attachment', function(){
109 check_modal();
110 });
111
112 // On page load in upload.php check if item param exists
113 if ( $('.upload-php').length > 0 && get_var('item') ) {
114 check_modal();
115 }
116
117 // On media clicked
118 $('#insert-media-button').on('click.imagify', function() {
119 var waitContent = setInterval( function() {
120 if ( $('.media-frame-content').find('.attachments').length > 0 ) {
121 $('.media-frame-content').find('.attachments').on('click.imagify', '.attachment', function(){
122 check_modal();
123 });
124 clearInterval(waitContent);
125 }
126 }, 100);
127 });
128
129 /*
130 * Mini chart
131 *
132 * @param {element} canvas
133 */
134 function draw_me_a_chart( canvas ) {
135 canvas.each(function(){
136
137 var the_value = parseInt( $(this).closest('.imagify-chart').next('.imagify-chart-value').text() ),
138 overviewData = [
139 {
140 value: the_value,
141 color: '#00B3D3'
142 },
143 {
144 value: 100 - the_value,
145 color: '#D8D8D8'
146 }
147 ],
148 overviewDoughnut = new Chart( $(this)[0].getContext('2d')).Doughnut(overviewData, {
149 segmentStrokeColor : '#FFF',
150 segmentStrokeWidth : 1,
151 animateRotate : true,
152 tooltipEvents : []
153 });
154 });
155 }
156 draw_me_a_chart( $('.imagify-chart-container').find('canvas') );
157 });