| @@ -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,9 +33,9 @@ | ||
| 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 | 39 | if (response.hasOwnProperty('files')) { |
| 37 | 40 | minify.updateFilesLists(response.files); |
| 38 | 41 | minify.updateStats(response.files); |
| @@ -46,9 +49,9 @@ | ||
| 46 | 49 | * Removes the entire cache dir. |
| 47 | 50 | * Use with caution, as cached html may still reference those files. |
| 48 | 51 | */ |
| 49 | 52 | $('.purge_all_minify_cache').on('click', function() { |
| 50 | - $.blockUI(); | |
| 53 | + block_ui(wpoptimize.clearing_cache); | |
| 51 | 54 | send_command('purge_all_minify_cache', null, function(response) { |
| 52 | 55 | if (response.hasOwnProperty('files')) { |
| 53 | 56 | minify.updateFilesLists(response.files); |
| 54 | 57 | minify.updateStats(response.files); |
| @@ -58,12 +61,12 @@ | ||
| 58 | 61 | }); |
| 59 | 62 | }); |
| 60 | 63 | |
| 61 | 64 | /** |
| 62 | - * Forces minifiy to create a new cache, safe to use | |
| 65 | + * Forces minify to create a new cache, safe to use | |
| 63 | 66 | */ |
| 64 | 67 | $('.minify_increment_cache').on('click', function() { |
| 65 | - $.blockUI(); | |
| 68 | + block_ui(wpoptimize.creating_cache); | |
| 66 | 69 | send_command('minify_increment_cache', null, function(response) { |
| 67 | 70 | if (response.hasOwnProperty('files')) { |
| 68 | 71 | minify.updateFilesLists(response.files); |
| 69 | 72 | minify.updateStats(response.files); |
| @@ -71,13 +74,12 @@ | ||
| 71 | 74 | }).always(function() { |
| 72 | 75 | $.unblockUI(); |
| 73 | 76 | }); |
| 74 | 77 | }); |
| 75 | - | |
| 76 | 78 | |
| 77 | 79 | // ======= SLIDERS ======== |
| 78 | 80 | // Generic slider save |
| 79 | - $('#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() { | |
| 80 | 82 | $(this).closest('form').data('need_saving', true); |
| 81 | 83 | }); |
| 82 | 84 | |
| 83 | 85 | $('input[type=checkbox].wpo-save-setting').on('change', function(e) { |
| @@ -85,9 +87,9 @@ | ||
| 85 | 87 | val = input.prop('checked'), |
| 86 | 88 | name = input.prop('name'), |
| 87 | 89 | data = {}; |
| 88 | 90 | data[name] = val; |
| 89 | - $.blockUI(); | |
| 91 | + block_ui(wpoptimize.saving); | |
| 90 | 92 | send_command('save_minify_settings', data, function(response) { |
| 91 | 93 | if (response.success) { |
| 92 | 94 | input.trigger('wp-optimize/minify/saved_setting'); |
| 93 | 95 | if (response.hasOwnProperty('files')) { |
| @@ -112,24 +114,45 @@ | ||
| 112 | 114 | $('#wpo_min_enable_minify').on('wp-optimize/minify/saved_setting', function() { |
| 113 | 115 | |
| 114 | 116 | $(this).closest('.wpo_section').toggleClass('wpo-feature-is-disabled', !$(this).is(':checked')); |
| 115 | 117 | }); |
| 116 | - | |
| 118 | + | |
| 117 | 119 | // Toggle wpo-feature-is-disabled class |
| 118 | 120 | $('#wpo_min_enable_minify_css, #wpo_min_enable_minify_js') |
| 119 | - // Set value on status change | |
| 121 | + // Update UI when setting is saved | |
| 120 | 122 | .on('wp-optimize/minify/saved_setting', function() { |
| 121 | - $('#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)); | |
| 122 | 124 | }) |
| 123 | - // Set value on page load | |
| 125 | + // Initialize UI on page load | |
| 124 | 126 | .each(function() { |
| 125 | - $('#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)); | |
| 126 | 128 | }); |
| 127 | - | |
| 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 | + | |
| 128 | 151 | // slider enable Debug mode |
| 129 | 152 | $('#wpo_min_enable_minify_debug').on('wp-optimize/minify/saved_setting', function() { |
| 130 | 153 | // Refresh the page as it's needed to show the extra options |
| 131 | - $.blockUI({message: '<h1>'+wpoptimize.page_refresh+'</h1>'}); | |
| 154 | + block_ui(wpoptimize.page_refresh); | |
| 132 | 155 | location.href = $('#wp-optimize-nav-tab-wpo_minify-advanced').prop('href'); |
| 133 | 156 | }); |
| 134 | 157 | |
| 135 | 158 | // Edit default exclusions |
| @@ -137,8 +160,18 @@ | ||
| 137 | 160 | // Show exclusions section |
| 138 | 161 | $('.wpo-minify-default-exclusions').toggleClass('hidden', !$(this).prop('checked')); |
| 139 | 162 | }); |
| 140 | 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 | + | |
| 141 | 174 | // Save settings |
| 142 | 175 | $('.wp-optimize-save-minify-settings').on('click', function(e) { |
| 143 | 176 | e.preventDefault(); |
| 144 | 177 | var btn = $(this), |
| @@ -146,11 +179,16 @@ | ||
| 146 | 179 | success_icon = spinner.next(), |
| 147 | 180 | $need_refresh_btn = null; |
| 148 | 181 | |
| 149 | 182 | spinner.show(); |
| 150 | - $.blockUI(); | |
| 183 | + block_ui(wpoptimize.saving); | |
| 151 | 184 | |
| 152 | 185 | var data = {}; |
| 186 | + | |
| 187 | + var merge_state = { | |
| 188 | + js: null, | |
| 189 | + css: null | |
| 190 | + }; | |
| 153 | 191 | |
| 154 | 192 | var tabs = $('[data-whichpage="wpo_minify"] .wp-optimize-nav-tab-contents form'); |
| 155 | 193 | tabs.each(function() { |
| 156 | 194 | var tab = $(this); |
| @@ -156,8 +194,16 @@ | ||
| 156 | 194 | var tab = $(this); |
| 157 | 195 | if (true === tab.data('need_saving')) { |
| 158 | 196 | data = Object.assign(data, gather_data(tab)); |
| 159 | 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 | + } | |
| 160 | 206 | } |
| 161 | 207 | }); |
| 162 | 208 | |
| 163 | 209 | send_command('save_minify_settings', data, function(response) { |
| @@ -172,8 +218,14 @@ | ||
| 172 | 218 | if (response.hasOwnProperty('files')) { |
| 173 | 219 | minify.updateFilesLists(response.files); |
| 174 | 220 | minify.updateStats(response.files); |
| 175 | 221 | } |
| 222 | + | |
| 223 | + $.each(merge_state, function(type, enabled) { | |
| 224 | + if (null !== enabled) { | |
| 225 | + toggle_minify_notice(type, enabled, false); | |
| 226 | + } | |
| 227 | + }); | |
| 176 | 228 | |
| 177 | 229 | spinner.hide(); |
| 178 | 230 | success_icon.show(); |
| 179 | 231 | setTimeout(function() { |
| @@ -184,19 +236,64 @@ | ||
| 184 | 236 | }).always(function() { |
| 185 | 237 | $.unblockUI(); |
| 186 | 238 | }); |
| 187 | 239 | }) |
| 188 | - | |
| 240 | + | |
| 189 | 241 | // Dismiss information notice |
| 190 | - $('.wp-optimize-minify-status-information-notice').on('click', '.notice-dismiss', function(e) { | |
| 242 | + $('.wpo_section_notice_minify').on('click', '.notice-dismiss', function(e) { | |
| 191 | 243 | e.preventDefault(); |
| 192 | - send_command('hide_minify_notice'); | |
| 244 | + toggle_minify_notice('minify', null, true); | |
| 193 | 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 | + } | |
| 194 | 285 | |
| 195 | 286 | // Show logs |
| 196 | 287 | $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.log', function(e) { |
| 197 | 288 | e.preventDefault(); |
| 198 | 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 | + } | |
| 199 | 296 | }); |
| 200 | 297 | |
| 201 | 298 | // Delete log file |
| 202 | 299 | $('#wpo_min_jsprocessed, #wpo_min_cssprocessed').on('click', '.delete-file', function(e) { |
| @@ -208,9 +305,9 @@ | ||
| 208 | 305 | alert(wpoptimize.cache_file_not_found); |
| 209 | 306 | return false; |
| 210 | 307 | } |
| 211 | 308 | |
| 212 | - $.blockUI(); | |
| 309 | + block_ui(wpoptimize.deleting); | |
| 213 | 310 | send_command('delete_minify_cache_file', filename, function(response) { |
| 214 | 311 | if('' !== response.files) { |
| 215 | 312 | minify.updateFilesLists(response.files); |
| 216 | 313 | minify.updateStats(response.files); |
| @@ -225,103 +322,86 @@ | ||
| 225 | 322 | $.unblockUI(); |
| 226 | 323 | }); |
| 227 | 324 | }); |
| 228 | 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 | + | |
| 229 | 344 | // Handle js excludes |
| 230 | 345 | $('#wpo_min_jsprocessed').on('click', '.exclude', function(e) { |
| 231 | 346 | e.preventDefault(); |
| 232 | - var el = $(this); | |
| 233 | - var excluded_file = get_excluded_file(el); | |
| 234 | - add_excluded_js_file(excluded_file); | |
| 235 | - tab_need_saving('js'); | |
| 236 | - highlight_excluded_item(el); | |
| 347 | + get_url_and_tab_saving($(this), '#exclude_js', 'js'); | |
| 237 | 348 | }); |
| 238 | 349 | |
| 239 | 350 | // Handle css excludes |
| 240 | 351 | $('#wpo_min_cssprocessed').on('click', '.exclude', function(e) { |
| 241 | 352 | e.preventDefault(); |
| 242 | - var el = $(this); | |
| 243 | - var excluded_file = get_excluded_file(el); | |
| 244 | - add_excluded_css_file(excluded_file); | |
| 245 | - tab_need_saving('css'); | |
| 246 | - highlight_excluded_item(el); | |
| 353 | + get_url_and_tab_saving($(this), '#exclude_css', 'css'); | |
| 247 | 354 | }); |
| 248 | 355 | |
| 249 | - /** | |
| 250 | - * Get excluded file url | |
| 251 | - * | |
| 252 | - * @param {HTMLElement} el | |
| 253 | - * | |
| 254 | - * @return {string} | |
| 255 | - */ | |
| 256 | - function get_excluded_file(el) { | |
| 257 | - return el.data('url'); | |
| 258 | - } | |
| 259 | - | |
| 260 | - /** | |
| 261 | - * Exclude js file | |
| 262 | - * | |
| 263 | - * @param {string} excluded_file File url | |
| 264 | - */ | |
| 265 | - function add_excluded_js_file(excluded_file) { | |
| 266 | - var $js_textarea = $('#exclude_js'); | |
| 267 | - var list_of_excluded_files = $js_textarea.val(); | |
| 268 | - list_of_excluded_files += excluded_file + '\n'; | |
| 269 | - $js_textarea.val(list_of_excluded_files); | |
| 270 | - } | |
| 271 | - | |
| 272 | - /** | |
| 273 | - * Exclude css file | |
| 274 | - * | |
| 275 | - * @param {string} excluded_file File url | |
| 276 | - */ | |
| 277 | - function add_excluded_css_file(excluded_file) { | |
| 278 | - var $css_textarea = $('#exclude_css'); | |
| 279 | - var list_of_excluded_files = $css_textarea.val(); | |
| 280 | - list_of_excluded_files += excluded_file + '\n'; | |
| 281 | - $css_textarea.val(list_of_excluded_files); | |
| 282 | - } | |
| 283 | - | |
| 284 | 356 | // Handle defer |
| 285 | 357 | $('#wpo_min_jsprocessed').on('click', '.defer', function(e) { |
| 286 | 358 | e.preventDefault(); |
| 287 | - add_deferred_file($(this)); | |
| 359 | + get_url_and_tab_saving($(this), '#async_js', 'js'); | |
| 288 | 360 | }); |
| 289 | 361 | |
| 290 | 362 | // Handle async loading |
| 291 | 363 | $('#wpo_min_cssprocessed').on('click', '.async', function(e) { |
| 292 | 364 | e.preventDefault(); |
| 293 | - add_async_file($(this)); | |
| 365 | + get_url_and_tab_saving($(this), '#async_css', 'css'); | |
| 294 | 366 | }); |
| 295 | - | |
| 367 | + | |
| 296 | 368 | /** |
| 297 | - * Add deferred file | |
| 369 | + * Get url from an element and then save it | |
| 298 | 370 | * |
| 299 | - * @param {HTMLElement} el target element | |
| 371 | + * @param {HTMLElement} el | |
| 372 | + * @param {string} target_el_id | |
| 373 | + * @param {string} tab_name | |
| 374 | + * | |
| 375 | + * @return void | |
| 300 | 376 | */ |
| 301 | - function add_deferred_file(el) { | |
| 302 | - var deferred_file = el.data('url'); | |
| 303 | - var $async_js_textarea = $('#async_js'); | |
| 304 | - var list_of_deferred_files = $async_js_textarea.val(); | |
| 305 | - list_of_deferred_files += deferred_file + '\n'; | |
| 306 | - $async_js_textarea.val(list_of_deferred_files); | |
| 307 | - 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); | |
| 308 | 385 | highlight_excluded_item(el); |
| 309 | 386 | } |
| 310 | - | |
| 387 | + | |
| 311 | 388 | /** |
| 312 | - * Add asynchronously loading file | |
| 389 | + * Add url to the next line of the element textarea | |
| 313 | 390 | * |
| 314 | - * @param {HTMLElement} el target element | |
| 391 | + * @param {string} target_el_id | |
| 392 | + * @param {string} file_url | |
| 393 | + * | |
| 394 | + * @return void | |
| 315 | 395 | */ |
| 316 | - function add_async_file(el) { | |
| 317 | - var async_file = el.data('url'); | |
| 318 | - var $async_css_textarea = $('#async_css'); | |
| 319 | - var list_of_async_files = $async_css_textarea.val(); | |
| 320 | - list_of_async_files += async_file + '\n'; | |
| 321 | - $async_css_textarea.val(list_of_async_files); | |
| 322 | - tab_need_saving('css'); | |
| 323 | - 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); | |
| 324 | 404 | } |
| 325 | 405 | |
| 326 | 406 | /** |
| 327 | 407 | * |
| @@ -373,10 +453,9 @@ | ||
| 373 | 453 | /** |
| 374 | 454 | * Minify Preloader functionality |
| 375 | 455 | */ |
| 376 | 456 | var run_minify_preload_btn = $('#wp_optimize_run_minify_preload'), |
| 377 | - minify_preload_status_el = $('#wp_optimize_preload_minify_status'), | |
| 378 | - check_status_interval = null; | |
| 457 | + minify_preload_status_el = $('#wp_optimize_preload_minify_status'); | |
| 379 | 458 | |
| 380 | 459 | run_minify_preload_btn.on('click', function() { |
| 381 | 460 | var btn = $(this), |
| 382 | 461 | is_running = btn.data('running'), |
| @@ -385,10 +464,11 @@ | ||
| 385 | 464 | btn.prop('disabled', true); |
| 386 | 465 | |
| 387 | 466 | if (is_running) { |
| 388 | 467 | btn.data('running', false); |
| 389 | - clearInterval(check_status_interval); | |
| 390 | - check_status_interval = null; | |
| 468 | + | |
| 469 | + heartbeat.cancel_agents(heartbeat_agents); | |
| 470 | + | |
| 391 | 471 | send_command( |
| 392 | 472 | 'cancel_minify_preload', |
| 393 | 473 | null, |
| 394 | 474 | function(response) { |
| @@ -451,18 +531,20 @@ | ||
| 451 | 531 | run_update_minify_preload_status(); |
| 452 | 532 | } |
| 453 | 533 | |
| 454 | 534 | /** |
| 455 | - * Create interval action for update preloader status. | |
| 535 | + * Create heartbeat agent action for update preloader status. | |
| 456 | 536 | * |
| 457 | 537 | * @return void |
| 458 | 538 | */ |
| 459 | 539 | function run_update_minify_preload_status() { |
| 460 | - 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 | + }); | |
| 461 | 545 | |
| 462 | - check_status_interval = setInterval(function() { | |
| 463 | - update_minify_preload_status(); | |
| 464 | - }, 5000); | |
| 546 | + if (null !== agent) heartbeat_agents.push(agent); | |
| 465 | 547 | } |
| 466 | 548 | |
| 467 | 549 | /** |
| 468 | 550 | * Update minify preload status ajax action. |
| @@ -468,22 +550,19 @@ | ||
| 468 | 550 | * Update minify preload status ajax action. |
| 469 | 551 | * |
| 470 | 552 | * @return void |
| 471 | 553 | */ |
| 472 | - function update_minify_preload_status() { | |
| 473 | - send_command('get_minify_preload_status', null, function(response) { | |
| 474 | - if (response.done) { | |
| 475 | - run_minify_preload_btn.val(wpoptimize.run_now); | |
| 476 | - run_minify_preload_btn.data('running', false); | |
| 477 | - clearInterval(check_status_interval); | |
| 478 | - check_status_interval = null; | |
| 479 | - } else { | |
| 480 | - run_minify_preload_btn.val(wpoptimize.cancel); | |
| 481 | - run_minify_preload_btn.data('running', true); | |
| 482 | - } | |
| 483 | - minify_preload_status_el.text(response.message); | |
| 484 | - update_minify_size_information(response); | |
| 485 | - }); | |
| 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); | |
| 486 | 565 | } |
| 487 | 566 | |
| 488 | 567 | /** |
| 489 | 568 | * Run update information about minify size. |
| @@ -493,8 +572,16 @@ | ||
| 493 | 572 | function update_minify_size_information(response) { |
| 494 | 573 | $('#wpo_min_cache_size').text(response.size); |
| 495 | 574 | $('#wpo_min_cache_total_size').text(response.total_size); |
| 496 | 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 | + | |
| 497 | 584 | return this; |
| 498 | 585 | } |
| 499 | 586 | |
| 500 | 587 | /** |
| @@ -528,9 +615,9 @@ | ||
| 528 | 615 | if ($('#'+this.uid).length == 0) { |
| 529 | 616 | $('#wpo_min_jsprocessed ul.processed').append('\ |
| 530 | 617 | <li id="'+this.uid+'">\ |
| 531 | 618 | <span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+'</a> ('+this.fsize+')</span>\ |
| 532 | - <a href="#" class="log">' + wpoptimize.toggle_info + '</a>\ | |
| 619 | + <a href="#" class="log">' + wpoptimize.show_information + '</a>\ | |
| 533 | 620 | <a href="#" class="delete-file" data-filename="' + this.filename + '">' + wpoptimize.delete_file + '</a>\ |
| 534 | 621 | <div class="hidden save_notice">\ |
| 535 | 622 | <p>' + wpoptimize.added_notice + '</p>\ |
| 536 | 623 | <p><button class="button button-primary save-exclusions">' + wpoptimize.save_notice + '</button></p>\ |
| @@ -551,9 +638,9 @@ | ||
| 551 | 638 | if ($('#'+this.uid).length == 0) { |
| 552 | 639 | $('#wpo_min_cssprocessed ul.processed').append('\ |
| 553 | 640 | <li id="'+this.uid+'">\ |
| 554 | 641 | <span class="filename"><a href="'+this.file_url+'" target="_blank">'+this.filename+'</a> ('+this.fsize+')</span>\ |
| 555 | - <a href="#" class="log">' + wpoptimize.toggle_info + '</a>\ | |
| 642 | + <a href="#" class="log">' + wpoptimize.show_information + '</a>\ | |
| 556 | 643 | <a href="#" class="delete-file" data-filename="' + this.filename + '">' + wpoptimize.delete_file + '</a>\ |
| 557 | 644 | <div class="hidden save_notice">\ |
| 558 | 645 | <p>' + wpoptimize.added_to_list + '</p>\ |
| 559 | 646 | <p><button class="button button-primary save-exclusions">' + wpoptimize.save_notice + '</button></p>\ |
| @@ -563,9 +650,8 @@ | ||
| 563 | 650 | '); |
| 564 | 651 | } |
| 565 | 652 | }); |
| 566 | 653 | } |
| 567 | - | |
| 568 | 654 | $('#wpo_min_cssprocessed ul.processed .no-files-yet').toggle(!data.css.length); |
| 569 | 655 | |
| 570 | 656 | // Remove <li> if it's not in the files array |
| 571 | 657 | $('#wpo_min_jsprocessed ul.processed > li, #wpo_min_cssprocessed ul.processed > li').each(function () { |
| @@ -586,9 +672,9 @@ | ||
| 586 | 672 | } |
| 587 | 673 | }; |
| 588 | 674 | |
| 589 | 675 | /** |
| 590 | - * Gather data from the given form | |
| 676 | + * Gather data from the given form | |
| 591 | 677 | * |
| 592 | 678 | * @param {HTMLFormElement} form |
| 593 | 679 | * |
| 594 | 680 | * @returns {Array} Array of collected data from the form |
| @@ -608,17 +694,17 @@ | ||
| 608 | 694 | }); |
| 609 | 695 | return data; |
| 610 | 696 | } |
| 611 | 697 | |
| 612 | - /** | |
| 613 | - * Reduces the form elements array into an object | |
| 614 | - * | |
| 615 | - * @param {Object} collection An empty object | |
| 616 | - * @param {*} item form input element as array element | |
| 617 | - * | |
| 618 | - * @returns {Object} collection An object of form data | |
| 619 | - */ | |
| 620 | - function form_serialize_reduce_cb(collection, item) { | |
| 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) { | |
| 621 | 707 | // Ignore items containing [], which we expect to be returned as arrays |
| 622 | 708 | if (item.name.includes('[]')) return collection; |
| 623 | 709 | collection[item.name] = item.value; |
| 624 | 710 | return collection; |
| @@ -636,5 +722,5 @@ | ||
| 636 | 722 | } |
| 637 | 723 | |
| 638 | 724 | wp_optimize.minify = minify; |
| 639 | 725 | |
| 640 | -})(jQuery); | |
| 726 | +})(jQuery); | |