PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | js/minify.js +287 -156 3.2.5 → 4.7.0 View file →
@@ -1,8 +1,11 @@
1 1 (function ($) {
2 2 var wp_optimize = window.wp_optimize || {};
3 + var block_ui = wp_optimize.block_ui;
3 4 var send_command = wp_optimize.send_command;
4 5 var refresh_frequency = wpoptimize.refresh_frequency || 30000;
6 + var heartbeat = WP_Optimize_Heartbeat();
7 + var heartbeat_agents = [];
5 8
6 9 if (!send_command) {
7 10 console.error('WP-Optimize Minify: wp_optimize.send_command is required.');
8 11 return;
@@ -30,12 +33,14 @@
30 33 * The standard handler for clearing the cache. Safe to use
31 34 */
32 35 $('.purge_minify_cache').on('click', function(e) {
33 36 e.preventDefault();
34 - $.blockUI();
37 + block_ui(wpoptimize.clearing_cache);
35 38 send_command('purge_minify_cache', null, function(response) {
36 - minify.updateFilesLists(response.files);
37 - minify.updateStats(response.files);
39 + if (response.hasOwnProperty('files')) {
40 + minify.updateFilesLists(response.files);
41 + minify.updateStats(response.files);
42 + }
38 43 }).always(function() {
39 44 $.unblockUI();
40 45 });
41 46 });
@@ -44,12 +49,14 @@
44 49 * Removes the entire cache dir.
45 50 * Use with caution, as cached html may still reference those files.
46 51 */
47 52 $('.purge_all_minify_cache').on('click', function() {
48 - $.blockUI();
53 + block_ui(wpoptimize.clearing_cache);
49 54 send_command('purge_all_minify_cache', null, function(response) {
50 - minify.updateFilesLists(response.files);
51 - minify.updateStats(response.files);
55 + if (response.hasOwnProperty('files')) {
56 + minify.updateFilesLists(response.files);
57 + minify.updateStats(response.files);
58 + }
52 59 }).always(function() {
53 60 $.unblockUI();
54 61 });
55 62 });
@@ -54,12 +61,12 @@
54 61 });
55 62 });
56 63
57 64 /**
58 - * Forces minifiy to create a new cache, safe to use
65 + * Forces minify to create a new cache, safe to use
59 66 */
60 67 $('.minify_increment_cache').on('click', function() {
61 - $.blockUI();
68 + block_ui(wpoptimize.creating_cache);
62 69 send_command('minify_increment_cache', null, function(response) {
63 70 if (response.hasOwnProperty('files')) {
64 71 minify.updateFilesLists(response.files);
65 72 minify.updateStats(response.files);
@@ -67,13 +74,12 @@
67 74 }).always(function() {
68 75 $.unblockUI();
69 76 });
70 77 });
71 -
72 78
73 79 // ======= SLIDERS ========
74 80 // Generic slider save
75 - $('#wp-optimize-nav-tab-wpo_minify-status-contents form :input, #wp-optimize-nav-tab-wpo_minify-js-contents form :input, #wp-optimize-nav-tab-wpo_minify-css-contents form :input, #wp-optimize-nav-tab-wpo_minify-font-contents form :input, #wp-optimize-nav-tab-wpo_minify-settings-contents form :input, #wp-optimize-nav-tab-wpo_minify-advanced-contents form :input').on('change', function() {
81 + $('#wp-optimize-nav-tab-wpo_minify-status-contents form :input, #wp-optimize-nav-tab-wpo_minify-js-contents form :input, #wp-optimize-nav-tab-wpo_minify-css-contents form :input, #wp-optimize-nav-tab-wpo_minify-font-contents form :input, #wp-optimize-nav-tab-wpo_minify-analytics-contents form :input, #wp-optimize-nav-tab-wpo_minify-settings-contents form :input, #wp-optimize-nav-tab-wpo_minify-advanced-contents form :input').on('change', function() {
76 82 $(this).closest('form').data('need_saving', true);
77 83 });
78 84
79 85 $('input[type=checkbox].wpo-save-setting').on('change', function(e) {
@@ -81,9 +87,9 @@
81 87 val = input.prop('checked'),
82 88 name = input.prop('name'),
83 89 data = {};
84 90 data[name] = val;
85 - $.blockUI();
91 + block_ui(wpoptimize.saving);
86 92 send_command('save_minify_settings', data, function(response) {
87 93 if (response.success) {
88 94 input.trigger('wp-optimize/minify/saved_setting');
89 95 if (response.hasOwnProperty('files')) {
@@ -108,24 +114,45 @@
108 114 $('#wpo_min_enable_minify').on('wp-optimize/minify/saved_setting', function() {
109 115
110 116 $(this).closest('.wpo_section').toggleClass('wpo-feature-is-disabled', !$(this).is(':checked'));
111 117 });
112 -
118 +
113 119 // Toggle wpo-feature-is-disabled class
114 120 $('#wpo_min_enable_minify_css, #wpo_min_enable_minify_js')
115 - // Set value on status change
121 + // Update UI when setting is saved
116 122 .on('wp-optimize/minify/saved_setting', function() {
117 - $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + $(this).data('tabname') + '"] span.disabled').toggleClass('hidden', $(this).is(':checked'));
123 + toggle_minify_tab_section($(this));
118 124 })
119 - // Set value on page load
125 + // Initialize UI on page load
120 126 .each(function() {
121 - $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + $(this).data('tabname') + '"] span.disabled').toggleClass('hidden', $(this).is(':checked'));
127 + toggle_minify_tab_section($(this));
122 128 });
123 -
129 +
130 + /**
131 + * Toggle the UI state of a minify tab section based on the associated checkbox state.
132 + *
133 + * - For JS minification, only elements marked with `.show-if-enabled` are toggled.
134 + *
135 + * @param {jQuery} $el The checkbox element controlling the minified setting
136 + *
137 + * @return {void}
138 + */
139 + function toggle_minify_tab_section($el) {
140 + var tab_name = $el.data('tabname');
141 + var tab_id = '#wpo_section_' + tab_name;
142 + var is_checked = $el.is(':checked');
143 +
144 + var $section = $el.is('#wpo_min_enable_minify_js') ? $(tab_id + ' .show-if-enabled') : $(tab_id);
145 +
146 + $('#wp-optimize-nav-tab-wrapper__wpo_minify a[data-tab="' + tab_name + '"] span.disabled').toggleClass('hidden', is_checked);
147 +
148 + $section.toggleClass('wpo-disabled-section', !is_checked);
149 + }
150 +
124 151 // slider enable Debug mode
125 152 $('#wpo_min_enable_minify_debug').on('wp-optimize/minify/saved_setting', function() {
126 153 // Refresh the page as it's needed to show the extra options
127 - $.blockUI({message: '<h1>'+wpoptimize.page_refresh+'</h1>'});
154 + block_ui(wpoptimize.page_refresh);
128 155 location.href = $('#wp-optimize-nav-tab-wpo_minify-advanced').prop('href');
129 156 });
130 157
131 158 // Edit default exclusions
@@ -133,8 +160,18 @@
133 160 // Show exclusions section
134 161 $('.wpo-minify-default-exclusions').toggleClass('hidden', !$(this).prop('checked'));
135 162 });
136 163
164 + var disable_google_fonts_processing = $('#disable_google_fonts_processing');
165 +
166 + function handle_disable_google_fonts_processing() {
167 + $('#wp-optimize-nav-tab-wpo_minify-font-contents .google_fonts_option:not(.skip-disable-processing)').prop('disabled', disable_google_fonts_processing.is(':checked'));
168 + }
169 +
170 + disable_google_fonts_processing.on('change', handle_disable_google_fonts_processing);
171 +
172 + handle_disable_google_fonts_processing();
173 +
137 174 // Save settings
138 175 $('.wp-optimize-save-minify-settings').on('click', function(e) {
139 176 e.preventDefault();
140 177 var btn = $(this),
@@ -142,11 +179,16 @@
142 179 success_icon = spinner.next(),
143 180 $need_refresh_btn = null;
144 181
145 182 spinner.show();
146 - $.blockUI();
183 + block_ui(wpoptimize.saving);
147 184
148 185 var data = {};
186 +
187 + var merge_state = {
188 + js: null,
189 + css: null
190 + };
149 191
150 192 var tabs = $('[data-whichpage="wpo_minify"] .wp-optimize-nav-tab-contents form');
151 193 tabs.each(function() {
152 194 var tab = $(this);
@@ -152,53 +194,24 @@
152 194 var tab = $(this);
153 195 if (true === tab.data('need_saving')) {
154 196 data = Object.assign(data, gather_data(tab));
155 197 tab.data('need_saving', false);
198 +
199 + if (typeof data.enable_merging_of_js !== 'undefined') {
200 + merge_state.js = data.enable_merging_of_js === 'true';
201 + }
202 +
203 + if (typeof data.enable_merging_of_css !== 'undefined') {
204 + merge_state.css = data.enable_merging_of_css === 'true';
205 + }
156 206 }
157 207 });
158 208
159 - /**
160 - * Gather data from the given form
161 - *
162 - * @param {HTMLFormElement} form
163 - *
164 - * @returns {Array} Array of collected data from the form
165 - */
166 - function gather_data(form) {
167 - var data = $(form).serializeArray().reduce(form_serialize_reduce_cb, {});
168 - $(form).find('input[type="checkbox"]').each(function (i) {
169 - var name = $(this).prop("name");
170 - if (name.includes('[]')) {
171 - if (!$(this).is(':checked')) return;
172 - var newName = name.replace('[]', '');
173 - if (!data[newName]) data[newName] = [];
174 - data[newName].push($(this).val());
175 - } else {
176 - data[name] = $(this).is(':checked') ? 'true' : 'false';
177 - }
178 - });
179 - return data;
180 - }
181 -
182 - /**
183 - * Reduces the form elements array into an object
184 - *
185 - * @param {Object} collection An empty object
186 - * @param {*} item form input element as array element
187 - *
188 - * @returns {Object} collection An object of form data
189 - */
190 - function form_serialize_reduce_cb(collection, item) {
191 - // Ignore items containing [], which we expect to be returned as arrays
192 - if (item.name.includes('[]')) return collection;
193 - collection[item.name] = item.value;
194 - return collection;
195 - }
196 209 send_command('save_minify_settings', data, function(response) {
197 210 if (response.hasOwnProperty('error')) {
198 211 // show error
199 212 console.log(response.error);
200 - $('.wpo-error__enabling-cache').removeClass('wpo_hidden').find('p').text(response.error.message);
213 + wp_optimize.notices.show_notice(response.success, response.error);
201 214 } else {
202 215 $('.wpo-error__enabling-cache').addClass('wpo_hidden').find('p').text('');
203 216 }
204 217
@@ -205,8 +218,14 @@
205 218 if (response.hasOwnProperty('files')) {
206 219 minify.updateFilesLists(response.files);
207 220 minify.updateStats(response.files);
208 221 }
222 +
223 + $.each(merge_state, function(type, enabled) {
224 + if (null !== enabled) {
225 + toggle_minify_notice(type, enabled, false);
226 + }
227 + });
209 228
210 229 spinner.hide();
211 230 success_icon.show();
212 231 setTimeout(function() {
@@ -217,116 +236,172 @@
217 236 }).always(function() {
218 237 $.unblockUI();
219 238 });
220 239 })
221 -
240 +
222 241 // Dismiss information notice
223 - $('.wp-optimize-minify-status-information-notice').on('click', '.notice-dismiss', function(e) {
242 + $('.wpo_section_notice_minify').on('click', '.notice-dismiss', function(e) {
224 243 e.preventDefault();
225 - send_command('hide_minify_notice');
244 + toggle_minify_notice('minify', null, true);
226 245 });
246 +
247 + $('.wpo_section_notice_js').on('click', '.notice-dismiss', function(e) {
248 + e.preventDefault();
249 + toggle_minify_notice('js', null, true);
250 + });
251 +
252 + $('.wpo_section_notice_css').on('click', '.notice-dismiss', function(e) {
253 + e.preventDefault();
254 + toggle_minify_notice('css', null, true);
255 + });
256 +
257 + /**
258 + * Toggle visibility of a WP-Optimize minify notice and persist user preference.
259 + *
260 + * @param {string} type - Notice type ('minify', 'js', 'css').
261 + * @param {boolean|null} merging_enabled - Whether the JS/CSS merging checkbox is enabled (true = checked, false = unchecked, null = not applicable).
262 + * @param {boolean} force_hide - Whether to hide forcefully (true) or (false).
263 + *
264 + * @returns {void}
265 + */
266 + function toggle_minify_notice(type, merging_enabled, force_hide) {
267 + var $notice = $('.wpo_section_notice_' + type);
268 + if (!$notice.length) return;
269 +
270 + send_command('toggle_minify_notice', { type: type, merging_enabled: merging_enabled, force_hide: force_hide }, function(response) {
271 + if (response.hasOwnProperty('success') && response.success === true) {
272 + if (response.hasOwnProperty('hide') && response.hide === true) {
273 + $notice.stop(true, true).slideUp(300);
274 + }
275 +
276 + if (response.hasOwnProperty('hide') && response.hide === false) {
277 + $notice.stop(true, true).slideDown(300);
278 + }
279 + }
280 + if (response.hasOwnProperty('message') && response.success !== true) {
281 + wp_optimize.notices.show_notice('error', response.message);
282 + }
283 + });
284 + }
227 285
228 286 // Show logs
229 287 $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.log', function(e) {
230 288 e.preventDefault();
231 289 $(this).nextAll('.wpo_min_log').slideToggle('fast');
290 + var link_text = $(this).text().trim();
291 + if (wpoptimize.show_information === link_text) {
292 + $(this).text(wpoptimize.hide_information);
293 + } else {
294 + $(this).text(wpoptimize.show_information);
295 + }
232 296 });
233 297
298 + // Delete log file
299 + $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.delete-file', function(e) {
300 + e.preventDefault();
301 +
302 + var filename = $(this).data('filename');
303 +
304 + if ('' === filename || undefined === filename) {
305 + alert(wpoptimize.cache_file_not_found);
306 + return false;
307 + }
308 +
309 + block_ui(wpoptimize.deleting);
310 + send_command('delete_minify_cache_file', filename, function(response) {
311 + if('' !== response.files) {
312 + minify.updateFilesLists(response.files);
313 + minify.updateStats(response.files);
314 + }
315 + if('' !== response.result) {
316 + alert(response.result);
317 + }
318 + if('' !== response.error) {
319 + alert(response.error);
320 + }
321 + }).always(function() {
322 + $.unblockUI();
323 + });
324 + });
325 +
326 + // Trigger combined meta.json file download
327 + $('.wpo-minify-download-metas-button').on('click', function(e) {
328 + e.preventDefault();
329 + send_command('get_minify_meta_files', null, function(response) {
330 + if (response.hasOwnProperty('error')) {
331 + // show error
332 + alert(response.error);
333 + return;
334 + }
335 +
336 + var link = document.body.appendChild(document.createElement('a'));
337 + link.setAttribute('download', 'combined_metas.json');
338 + link.setAttribute('style', "display:none;");
339 + link.setAttribute('href', 'data:text/json' + ';charset=UTF-8,' + encodeURIComponent(JSON.stringify(response.combined_metas)));
340 + link.click();
341 + })
342 + });
343 +
234 344 // Handle js excludes
235 345 $('#wpo_min_jsprocessed').on('click', '.exclude', function(e) {
236 346 e.preventDefault();
237 - var el = $(this);
238 - var excluded_file = get_excluded_file(el);
239 - add_excluded_js_file(excluded_file);
240 - tab_need_saving('js');
241 - highlight_excluded_item(el);
347 + get_url_and_tab_saving($(this), '#exclude_js', 'js');
242 348 });
243 349
244 350 // Handle css excludes
245 351 $('#wpo_min_cssprocessed').on('click', '.exclude', function(e) {
246 352 e.preventDefault();
247 - var el = $(this);
248 - var excluded_file = get_excluded_file(el);
249 - add_excluded_css_file(excluded_file);
250 - tab_need_saving('css');
251 - highlight_excluded_item(el);
353 + get_url_and_tab_saving($(this), '#exclude_css', 'css');
252 354 });
253 355
254 - /**
255 - * Get excluded file url
256 - *
257 - * @param {HTMLElement} el
258 - *
259 - * @return {string}
260 - */
261 - function get_excluded_file(el) {
262 - return el.data('url');
263 - }
264 -
265 - /**
266 - * Exclude js file
267 - *
268 - * @param {string} excluded_file File url
269 - */
270 - function add_excluded_js_file(excluded_file) {
271 - var $js_textarea = $('#exclude_js');
272 - var list_of_excluded_files = $js_textarea.val();
273 - list_of_excluded_files += excluded_file + '\n';
274 - $js_textarea.val(list_of_excluded_files);
275 - }
276 -
277 - /**
278 - * Exclude css file
279 - *
280 - * @param {string} excluded_file File url
281 - */
282 - function add_excluded_css_file(excluded_file) {
283 - var $css_textarea = $('#exclude_css');
284 - var list_of_excluded_files = $css_textarea.val();
285 - list_of_excluded_files += excluded_file + '\n';
286 - $css_textarea.val(list_of_excluded_files);
287 - }
288 -
289 356 // Handle defer
290 357 $('#wpo_min_jsprocessed').on('click', '.defer', function(e) {
291 358 e.preventDefault();
292 - add_deferred_file($(this));
359 + get_url_and_tab_saving($(this), '#async_js', 'js');
293 360 });
294 361
295 362 // Handle async loading
296 363 $('#wpo_min_cssprocessed').on('click', '.async', function(e) {
297 364 e.preventDefault();
298 - add_async_file($(this));
365 + get_url_and_tab_saving($(this), '#async_css', 'css');
299 366 });
300 -
367 +
301 368 /**
302 - * Add deferred file
369 + * Get url from an element and then save it
303 370 *
304 - * @param {HTMLElement} el target element
371 + * @param {HTMLElement} el
372 + * @param {string} target_el_id
373 + * @param {string} tab_name
374 + *
375 + * @return void
305 376 */
306 - function add_deferred_file(el) {
307 - var deferred_file = el.data('url');
308 - var $async_js_textarea = $('#async_js');
309 - var list_of_deferred_files = $async_js_textarea.val();
310 - list_of_deferred_files += deferred_file + '\n';
311 - $async_js_textarea.val(list_of_deferred_files);
312 - tab_need_saving('js');
377 + function get_url_and_tab_saving(el, target_el_id, tab_name) {
378 + var file_url = el.data('url');
379 + if ('' === file_url || undefined === file_url) {
380 + return;
381 + }
382 +
383 + add_url_to_next_line(target_el_id, file_url);
384 + tab_need_saving(tab_name);
313 385 highlight_excluded_item(el);
314 386 }
315 -
387 +
316 388 /**
317 - * Add asynchronously loading file
389 + * Add url to the next line of the element textarea
318 390 *
319 - * @param {HTMLElement} el target element
391 + * @param {string} target_el_id
392 + * @param {string} file_url
393 + *
394 + * @return void
320 395 */
321 - function add_async_file(el) {
322 - var async_file = el.data('url');
323 - var $async_css_textarea = $('#async_css');
324 - var list_of_async_files = $async_css_textarea.val();
325 - list_of_async_files += async_file + '\n';
326 - $async_css_textarea.val(list_of_async_files);
327 - tab_need_saving('css');
328 - highlight_excluded_item(el);
396 + function add_url_to_next_line(target_el_id, file_url) {
397 + var $textarea = $(target_el_id);
398 + var list_of_files = $textarea.val().trim();
399 + if ('' !== list_of_files) {
400 + list_of_files += '\n';
401 + }
402 + list_of_files += file_url;
403 + $textarea.val(list_of_files);
329 404 }
330 405
331 406 /**
332 407 *
@@ -378,10 +453,9 @@
378 453 /**
379 454 * Minify Preloader functionality
380 455 */
381 456 var run_minify_preload_btn = $('#wp_optimize_run_minify_preload'),
382 - minify_preload_status_el = $('#wp_optimize_preload_minify_status'),
383 - check_status_interval = null;
457 + minify_preload_status_el = $('#wp_optimize_preload_minify_status');
384 458
385 459 run_minify_preload_btn.on('click', function() {
386 460 var btn = $(this),
387 461 is_running = btn.data('running'),
@@ -390,10 +464,11 @@
390 464 btn.prop('disabled', true);
391 465
392 466 if (is_running) {
393 467 btn.data('running', false);
394 - clearInterval(check_status_interval);
395 - check_status_interval = null;
468 +
469 + heartbeat.cancel_agents(heartbeat_agents);
470 +
396 471 send_command(
397 472 'cancel_minify_preload',
398 473 null,
399 474 function(response) {
@@ -456,18 +531,20 @@
456 531 run_update_minify_preload_status();
457 532 }
458 533
459 534 /**
460 - * Create interval action for update preloader status.
535 + * Create heartbeat agent action for update preloader status.
461 536 *
462 537 * @return void
463 538 */
464 539 function run_update_minify_preload_status() {
465 - if (check_status_interval) return;
540 + var agent = heartbeat.add_agent({
541 + command: 'get_minify_preload_status',
542 + callback: update_minify_preload_status,
543 + _keep: false
544 + });
466 545
467 - check_status_interval = setInterval(function() {
468 - update_minify_preload_status();
469 - }, 5000);
546 + if (null !== agent) heartbeat_agents.push(agent);
470 547 }
471 548
472 549 /**
473 550 * Update minify preload status ajax action.
@@ -473,22 +550,19 @@
473 550 * Update minify preload status ajax action.
474 551 *
475 552 * @return void
476 553 */
477 - function update_minify_preload_status() {
478 - send_command('get_minify_preload_status', null, function(response) {
479 - if (response.done) {
480 - run_minify_preload_btn.val(wpoptimize.run_now);
481 - run_minify_preload_btn.data('running', false);
482 - clearInterval(check_status_interval);
483 - check_status_interval = null;
484 - } else {
485 - run_minify_preload_btn.val(wpoptimize.cancel);
486 - run_minify_preload_btn.data('running', true);
487 - }
488 - minify_preload_status_el.text(response.message);
489 - update_minify_size_information(response);
490 - });
554 + function update_minify_preload_status(response) {
555 + if (response.done) {
556 + run_minify_preload_btn.val(wpoptimize.run_now);
557 + run_minify_preload_btn.data('running', false);
558 + } else {
559 + run_minify_preload_btn.val(wpoptimize.cancel);
560 + run_minify_preload_btn.data('running', true);
561 + run_update_minify_preload_status();
562 + }
563 + minify_preload_status_el.text(response.message);
564 + update_minify_size_information(response);
491 565 }
492 566
493 567 /**
494 568 * Run update information about minify size.
@@ -498,8 +572,16 @@
498 572 function update_minify_size_information(response) {
499 573 $('#wpo_min_cache_size').text(response.size);
500 574 $('#wpo_min_cache_total_size').text(response.total_size);
501 575 }
576 +
577 + // switch for visibility (analytics setting tab).
578 + var $analytics = $('#wpo-analytics-hidden-content');
579 +
580 + $('#wpo_enable_analytics').on('change', function () {
581 + $analytics.css('display', $(this).prop('checked') ? 'block' : 'none');
582 + });
583 +
502 584 return this;
503 585 }
504 586
505 587 /**
@@ -513,12 +595,10 @@
513 595 stamp: new Date().getTime()
514 596 };
515 597
516 598 send_command('get_minify_cached_files', data, function(response) {
517 -
518 599 minify.updateFilesLists(response);
519 600 minify.updateStats(response);
520 -
521 601 });
522 602
523 603 if (refresh_frequency) setTimeout(minify.getFiles.bind(this), refresh_frequency);
524 604 }
@@ -523,8 +603,9 @@
523 603 if (refresh_frequency) setTimeout(minify.getFiles.bind(this), refresh_frequency);
524 604 }
525 605
526 606 minify.updateFilesLists = function(data) {
607 + if (null === data) return;
527 608 // reset
528 609 var wpominarr = [];
529 610
530 611 // js
@@ -534,9 +615,10 @@
534 615 if ($('#'+this.uid).length == 0) {
535 616 $('#wpo_min_jsprocessed ul.processed').append('\
536 617 <li id="'+this.uid+'">\
537 618 <span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+'</a> ('+this.fsize+')</span>\
538 - <a href="#" class="log">' + wpoptimize.toggle_info + '</a>\
619 + <a href="#" class="log">' + wpoptimize.show_information + '</a>\
620 + <a href="#" class="delete-file" data-filename="' + this.filename + '">' + wpoptimize.delete_file + '</a>\
539 621 <div class="hidden save_notice">\
540 622 <p>' + wpoptimize.added_notice + '</p>\
541 623 <p><button class="button button-primary save-exclusions">' + wpoptimize.save_notice + '</button></p>\
542 624 </div>\
@@ -556,9 +638,10 @@
556 638 if ($('#'+this.uid).length == 0) {
557 639 $('#wpo_min_cssprocessed ul.processed').append('\
558 640 <li id="'+this.uid+'">\
559 641 <span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+'</a> ('+this.fsize+')</span>\
560 - <a href="#" class="log">' + wpoptimize.toggle_info + '</a>\
642 + <a href="#" class="log">' + wpoptimize.show_information + '</a>\
643 + <a href="#" class="delete-file" data-filename="' + this.filename + '">' + wpoptimize.delete_file + '</a>\
561 644 <div class="hidden save_notice">\
562 645 <p>' + wpoptimize.added_to_list + '</p>\
563 646 <p><button class="button button-primary save-exclusions">' + wpoptimize.save_notice + '</button></p>\
564 647 </div>\
@@ -567,9 +650,8 @@
567 650 ');
568 651 }
569 652 });
570 653 }
571 -
572 654 $('#wpo_min_cssprocessed ul.processed .no-files-yet').toggle(!data.css.length);
573 655
574 656 // Remove <li> if it's not in the files array
575 657 $('#wpo_min_jsprocessed ul.processed > li, #wpo_min_cssprocessed ul.processed > li').each(function () {
@@ -588,8 +670,57 @@
588 670 $("#wpo_min_cache_time").html(this.enabled ? data.cacheTime : '-');
589 671 $("#wpo_min_cache_path").html(data.cachePath);
590 672 }
591 673 };
674 +
675 + /**
676 + * Gather data from the given form
677 + *
678 + * @param {HTMLFormElement} form
679 + *
680 + * @returns {Array} Array of collected data from the form
681 + */
682 + function gather_data(form) {
683 + var data = $(form).serializeArray().reduce(form_serialize_reduce_cb, {});
684 + $(form).find('input[type="checkbox"]').each(function (i) {
685 + var name = $(this).prop("name");
686 + if (name.includes('[]')) {
687 + if (!$(this).is(':checked')) return;
688 + var newName = name.replace('[]', '');
689 + if (!data[newName]) data[newName] = [];
690 + data[newName].push($(this).val());
691 + } else {
692 + data[name] = $(this).is(':checked') ? 'true' : 'false';
693 + }
694 + });
695 + return data;
696 + }
697 +
698 + /**
699 + * Reduces the form elements array into an object
700 + *
701 + * @param {Object} collection An empty object
702 + * @param {*} item form input element as array element
703 + *
704 + * @returns {Object} collection An object of form data
705 + */
706 + function form_serialize_reduce_cb(collection, item) {
707 + // Ignore items containing [], which we expect to be returned as arrays
708 + if (item.name.includes('[]')) return collection;
709 + collection[item.name] = item.value;
710 + return collection;
711 + }
712 +
713 + // Gather minify settings from all tabs
714 + wp_optimize.minify_settings = function() {
715 + var tabs = $('[data-whichpage="wpo_minify"] .wp-optimize-nav-tab-contents form');
716 + var data = {}
717 + tabs.each(function() {
718 + var tab = $(this);
719 + data = Object.assign(data, gather_data(tab));
720 + });
721 + return data;
722 + }
592 723
593 724 wp_optimize.minify = minify;
594 725
595 726 })(jQuery);