| @@ -68,9 +68,9 @@ | ||
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Handle Enable Gzip compression button click. |
| 71 | 71 | */ |
| 72 | - $('#wp_optimize_gzip_compression_enable').on('click', function() { | |
| 72 | + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '#wp_optimize_gzip_compression_enable', function() { | |
| 73 | 73 | var button = $(this), |
| 74 | 74 | loader = button.next(); |
| 75 | 75 | |
| 76 | 76 | loader.show(); |
| @@ -75,20 +75,13 @@ | ||
| 75 | 75 | |
| 76 | 76 | loader.show(); |
| 77 | 77 | |
| 78 | 78 | send_command('enable_gzip_compression', {enable: button.data('enable')}, function(response) { |
| 79 | - var gzip_status_message = $('#wpo_gzip_compression_status'); | |
| 80 | 79 | if (response) { |
| 81 | - if (response.enabled) { | |
| 82 | - button.text(wpoptimize.disable); | |
| 83 | - button.data('enable', '0'); | |
| 84 | - gzip_status_message.removeClass('wpo-disabled').addClass('wpo-enabled'); | |
| 85 | - } else { | |
| 86 | - button.text(wpoptimize.enable); | |
| 87 | - button.data('enable', '1'); | |
| 88 | - gzip_status_message.addClass('wpo-disabled').removeClass('wpo-enabled'); | |
| 89 | - } | |
| 90 | 80 | |
| 81 | + $('#wpo_gzip_compression_test_btn').trigger('click'); | |
| 82 | + | |
| 83 | + // Handle error message | |
| 91 | 84 | if (response.message) { |
| 92 | 85 | $('#wpo_gzip_compression_error_message').text(response.message).show(); |
| 93 | 86 | } else { |
| 94 | 87 | $('#wpo_gzip_compression_error_message').hide(); |
| @@ -111,11 +104,52 @@ | ||
| 111 | 104 | }); |
| 112 | 105 | }); |
| 113 | 106 | |
| 114 | 107 | /** |
| 108 | + * Handle Test again compressions button click | |
| 109 | + */ | |
| 110 | + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '#wpo_gzip_compression_test_btn', function() { | |
| 111 | + var btn = $(this); | |
| 112 | + | |
| 113 | + if (btn.prop('disabled')) return; | |
| 114 | + | |
| 115 | + btn.prop('disabled', true); | |
| 116 | + $('#wpo_gzip_compression_details').hide(); | |
| 117 | + $('#wpo_gzip_control_panel .wpo_shade').removeClass('hidden'); | |
| 118 | + | |
| 119 | + send_command('get_compression_test_results_html', {}, function(response) { | |
| 120 | + if (response.results_html) { | |
| 121 | + $('#wpo_gzip_compression_details').html(response.results_html); | |
| 122 | + } else { | |
| 123 | + $('#wpo_gzip_compression_details').text(wpoptimize.error_unexpected_response); | |
| 124 | + } | |
| 125 | + | |
| 126 | + if (response.gzip_compression_control_panel) { | |
| 127 | + $('#wpo_gzip_control_panel').html(response.gzip_compression_control_panel); | |
| 128 | + } | |
| 129 | + }).fail(function() { | |
| 130 | + alert(wpoptimize.error_unexpected_response); | |
| 131 | + }).always(function() { | |
| 132 | + $('#wpo_gzip_control_panel .wpo_shade').addClass('hidden'); | |
| 133 | + $('#wpo_gzip_compression_details').show(); | |
| 134 | + btn.prop('disabled', false); | |
| 135 | + }); | |
| 136 | + }); | |
| 137 | + | |
| 138 | + /** | |
| 139 | + * Update gzip test results when tab is activated | |
| 140 | + */ | |
| 141 | + $('#wp-optimize-wrap').on('tab-change/wpo_cache/gzip', function() { | |
| 142 | + if (!$('#wp-optimize-nav-tab-wpo_cache-gzip').data('activated')) { | |
| 143 | + $('#wp-optimize-nav-tab-wpo_cache-gzip').data('activated', true); | |
| 144 | + $('#wpo_gzip_compression_test_btn').trigger('click'); | |
| 145 | + } | |
| 146 | + }); | |
| 147 | + | |
| 148 | + /** | |
| 115 | 149 | * Manually check gzip status |
| 116 | 150 | */ |
| 117 | - $('.wpo-refresh-gzip-status').on('click', function(e) { | |
| 151 | + $('#wp-optimize-nav-tab-wpo_cache-gzip-contents').on('click', '.wpo-refresh-gzip-status', function(e) { | |
| 118 | 152 | e.preventDefault(); |
| 119 | 153 | $link = $(this); |
| 120 | 154 | $link.addClass('loading'); |
| 121 | 155 | send_command('get_gzip_compression_status', null, function(response) { |
| @@ -152,12 +186,12 @@ | ||
| 152 | 186 | if (isNaN(browser_cache_expire_days)) browser_cache_expire_days = 0; |
| 153 | 187 | if (isNaN(browser_cache_expire_hours)) browser_cache_expire_hours = 0; |
| 154 | 188 | |
| 155 | 189 | if (browser_cache_expire_days < 0 || browser_cache_expire_hours < 0) { |
| 156 | - $('#wpo_browser_cache_error_message').text(wpoptimize.please_use_positive_integers).show(); | |
| 190 | + alert(wpoptimize.please_use_positive_integers); | |
| 157 | 191 | return false; |
| 158 | 192 | } else if (browser_cache_expire_hours > 23) { |
| 159 | - $('#wpo_browser_cache_error_message').text(wpoptimize.please_use_valid_values).show(); | |
| 193 | + alert(wpoptimize.please_use_valid_values); | |
| 160 | 194 | return false; |
| 161 | 195 | } else { |
| 162 | 196 | $('#wpo_browser_cache_error_message').hide(); |
| 163 | 197 | } |
| @@ -167,46 +201,48 @@ | ||
| 167 | 201 | browser_cache_expire_hours_el.val(browser_cache_expire_hours); |
| 168 | 202 | |
| 169 | 203 | loader.show(); |
| 170 | 204 | |
| 171 | - send_command('enable_browser_cache', {browser_cache_expire_days: browser_cache_expire_days, browser_cache_expire_hours: browser_cache_expire_hours}, function(response) { | |
| 172 | - var cache_status_message = $('#wpo_browser_cache_status'); | |
| 173 | - var cache_status_field = $('#wpo_enable_browser_cache'); | |
| 174 | - if (response) { | |
| 175 | - if (response.enabled) { | |
| 176 | - button.text(wpoptimize.update); | |
| 177 | - cache_status_message.removeClass('wpo-disabled').addClass('wpo-enabled'); | |
| 178 | - cache_status_field.val('true'); | |
| 179 | - } else { | |
| 180 | - button.text(wpoptimize.enable); | |
| 181 | - cache_status_message.addClass('wpo-disabled').removeClass('wpo-enabled'); | |
| 182 | - cache_status_field.val('false'); | |
| 183 | - } | |
| 205 | + send_command('enable_browser_cache', | |
| 206 | + {browser_cache_expire_days: browser_cache_expire_days, | |
| 207 | + browser_cache_expire_hours: browser_cache_expire_hours}, function(response) { | |
| 208 | + var cache_status_message = $('#wpo_browser_cache_status'); | |
| 209 | + var cache_status_field = $('#wpo_enable_browser_cache'); | |
| 210 | + if (response) { | |
| 211 | + if (response.enabled) { | |
| 212 | + button.text(wpoptimize.update); | |
| 213 | + cache_status_message.removeClass('wpo-disabled').addClass('wpo-enabled'); | |
| 214 | + cache_status_field.val('true'); | |
| 215 | + } else { | |
| 216 | + button.text(wpoptimize.enable); | |
| 217 | + cache_status_message.addClass('wpo-disabled').removeClass('wpo-enabled'); | |
| 218 | + cache_status_field.val('false'); | |
| 219 | + } | |
| 184 | 220 | |
| 185 | - if (response.message) { | |
| 186 | - $('#wpo_browser_cache_message').text(response.message).show(); | |
| 187 | - } else { | |
| 188 | - $('#wpo_browser_cache_message').hide(); | |
| 189 | - } | |
| 221 | + if (response.message) { | |
| 222 | + $('#wpo_browser_cache_message').text(response.message).show(); | |
| 223 | + } else { | |
| 224 | + $('#wpo_browser_cache_message').hide(); | |
| 225 | + } | |
| 190 | 226 | |
| 191 | - if (response.error_message) { | |
| 192 | - $('#wpo_browser_cache_error_message').text(response.error_message).show(); | |
| 193 | - } else { | |
| 194 | - $('#wpo_browser_cache_error_message').hide(); | |
| 195 | - } | |
| 227 | + if (response.error_message) { | |
| 228 | + $('#wpo_browser_cache_error_message').text(response.error_message).show(); | |
| 229 | + } else { | |
| 230 | + $('#wpo_browser_cache_error_message').hide(); | |
| 231 | + } | |
| 196 | 232 | |
| 197 | - if (response.output) { | |
| 198 | - $('#wpo_browser_cache_output').html(response.output).show(); | |
| 233 | + if (response.output) { | |
| 234 | + $('#wpo_browser_cache_output').html(response.output).show(); | |
| 235 | + } else { | |
| 236 | + $('#wpo_browser_cache_output').hide(); | |
| 237 | + } | |
| 238 | + | |
| 199 | 239 | } else { |
| 200 | - $('#wpo_browser_cache_output').hide(); | |
| 240 | + alert(wpoptimize.error_unexpected_response); | |
| 201 | 241 | } |
| 202 | 242 | |
| 203 | - } else { | |
| 204 | - alert(wpoptimize.error_unexpected_response); | |
| 205 | - } | |
| 206 | - | |
| 207 | - loader.hide(); | |
| 208 | - }).fail(function() { | |
| 243 | + loader.hide(); | |
| 244 | + }).fail(function() { | |
| 209 | 245 | alert(wpoptimize.error_unexpected_response); |
| 210 | 246 | loader.hide(); |
| 211 | 247 | }); |
| 212 | 248 | }); |
| @@ -321,8 +357,10 @@ | ||
| 321 | 357 | // enable minify preload |
| 322 | 358 | $('#wp_optimize_run_minify_preload').prop('disabled', false); |
| 323 | 359 | $('#minify-preload').hide(); |
| 324 | 360 | } |
| 361 | + | |
| 362 | + $(document).trigger('wp-optimize/cache/toggle-status', {enabled: response.enabled}); | |
| 325 | 363 | |
| 326 | 364 | if (response.result) { |
| 327 | 365 | // If Result is true, show the success icon. |
| 328 | 366 | success_icon.show(); |