images
6 years ago
javascript
5 years ago
stylesheet
5 years ago
admin.php
5 years ago
connect.php
5 years ago
dashboard.php
5 years ago
diag.php
5 years ago
help.php
6 years ago
dashboard.php
650 lines
| 1 | <div> |
| 2 | <div class="row"> |
| 3 | <div class="col-md-12"> |
| 4 | <?php nitropack_display_admin_notices(); ?> |
| 5 | </div> |
| 6 | </div> |
| 7 | <div class="row"> |
| 8 | <div class="col-md-6 mb-3"> |
| 9 | <div class="card-overlay-blurrable np-widget" id="optimizations-widget"> |
| 10 | <div class="card card-d-item"> |
| 11 | <div class="card-body"> |
| 12 | <h5 class="card-title">Optimized Pages<span id="pending-optimizations-section" class="pull-right" style="display:none;font-size: 12px;color: #28a745">Processing <span id="pending-optimizations-count">X</span> page(s) in the background <i class="fa fa-spinner fa-spin"></i></span></h5> |
| 13 | <div class="row mt-4" data-hideable> |
| 14 | <div id="optimized-pages"><span data-optimized-pages-total>0</span></div> |
| 15 | <div id="last-cache-purge" class="text-secondary">Last cache purge: <span data-last-cache-purge>Never</span></div> |
| 16 | <div id="last-cache-purge-reason" class="text-secondary">Reason: <span data-purge-reason>Unknown</span></div> |
| 17 | </div> |
| 18 | <div class="row mt-4 optimizations-hidden" data-hideable> |
| 19 | <div class="optimizations-subcount"><span data-optimized-pages-mobile>0</span> mobile pages</div> |
| 20 | <div class="optimizations-subcount"><span data-optimized-pages-tablet>0</span> tablet pages</div> |
| 21 | <div class="optimizations-subcount"><span data-optimized-pages-desktop>0</span> desktop pages</div> |
| 22 | </div> |
| 23 | <div class="row mt-5 justify-content-center"> |
| 24 | <button id="optimizations-invalidate-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations">Invalidate Cache</button> |
| 25 | <button id="optimizations-purge-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations">Purge Cache</button> |
| 26 | </div> |
| 27 | </div> |
| 28 | </div> |
| 29 | </div> |
| 30 | </div> |
| 31 | <div class="col-md-6 mb-3"> |
| 32 | <div class="card-overlay-blurrable np-widget" id="plan-details-widget"> |
| 33 | <div class="card card-d-item"> |
| 34 | <div class="card-body"> |
| 35 | <h5 class="card-title">Plan</h5> |
| 36 | <div class="mt-3"> |
| 37 | <h5 class="font-weight-lighter"><span data-plan-title>Unknown</span> <a target="_blank" href="https://nitropack.io/user/billing" class="btn btn-primary btn-sm ml-3">Manage plan</a></h5> |
| 38 | </div> |
| 39 | <ul class="list-group list-group-flush" id="plan-quotas"> |
| 40 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Reset <span data-next-reset>No ETA</span></li> |
| 41 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center">Next Billing <span data-next-billing>No ETA</span></li> |
| 42 | </ul> |
| 43 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You will be notified if you approach the plan resource limit</p> |
| 44 | </div> |
| 45 | </div> |
| 46 | </div> |
| 47 | </div> |
| 48 | <div class="col-md-6 mb-3"> |
| 49 | <div class="card-overlay-blurrable np-widget" id="quicksetup-widget"> |
| 50 | <div class="card card-d-item"> |
| 51 | <div class="card-body"> |
| 52 | <h5 class="card-title">Optimization Mode</h5> |
| 53 | <p><small>Slide to change your settings. This will update the level of optimization.</small></p> |
| 54 | |
| 55 | <div id="range-container"> |
| 56 | <div id="labels"></div> |
| 57 | <div id="range-element"> |
| 58 | <div id="divisors"></div> |
| 59 | <input id="range" type="range" min="1" max="5" step="1" value="0" /> |
| 60 | </div> |
| 61 | </div> |
| 62 | |
| 63 | <div id="description"> |
| 64 | <div class="text dummy"> |
| 65 | <h6 class="text-success">Dummy</h6> |
| 66 | <p><small></small></p> |
| 67 | </div> |
| 68 | <div class="text standard"> |
| 69 | <h6 class="text-info">Standard</h6> |
| 70 | <p><small>A pre-defined configuration without much regard for a high score. Enough to get you up and running.</small></p> |
| 71 | </div> |
| 72 | <div class="text medium"> |
| 73 | <h6 class="text-success">Medium</h6> |
| 74 | <p><small>Well-balanced and suitable for most cases.</small></p> |
| 75 | </div> |
| 76 | <div class="text strong"> |
| 77 | <h6 class="text-warning">Strong</h6> |
| 78 | <p><small>Includes advanced features like automatic image lazy loading and font definition modification. May cause issues in some cases.</small></p> |
| 79 | </div> |
| 80 | <div class="text ludicrous"> |
| 81 | <h6 class="text-danger">Ludicrous</h6> |
| 82 | <p><small>A pre-defined configuration aiming to achieve the highest possible score. In some cases, it may cause issues with your site.</small></p> |
| 83 | </div> |
| 84 | <div class="text custom"> |
| 85 | <h6>Manual</h6> |
| 86 | <p><small>Use your own settings. <a id="manual-settings-url" href="javascript:void(0);" target="_blank">Click here</a> to configure them.</small></p> |
| 87 | </div> |
| 88 | </div> |
| 89 | </div> |
| 90 | </div> |
| 91 | </div> |
| 92 | </div> |
| 93 | <div class="col-md-6 mb-3"> |
| 94 | <div class="card-overlay-blurrable np-widget" id="settings-widget"> |
| 95 | <div class="card card-d-item"> |
| 96 | <div class="card-body"> |
| 97 | <h5 class="card-title">Settings</h5> |
| 98 | <ul class="list-group list-group-flush"> |
| 99 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 100 | <span>Cache Warmup</span> |
| 101 | <span id="loading-warmup-status"> |
| 102 | Loading cache warmup status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i> |
| 103 | </span> |
| 104 | <span id="warmup-toggle" style="display: none;"> |
| 105 | <label id="warmup-status-slider" class="switch"> |
| 106 | <input type="checkbox" id="warmup-status"> |
| 107 | <span class="slider"></span> |
| 108 | </label> |
| 109 | </span> |
| 110 | </li> |
| 111 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 112 | <span id="detecting-compression" style="display: none;">Testing current compression status <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span> |
| 113 | <span id="detected-compression">HTML Compression <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="Automatically detect whether compression is needed"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span> |
| 114 | <span> |
| 115 | <label class="switch"> |
| 116 | <input type="checkbox" id="compression-status" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>> |
| 117 | <span class="slider"></span> |
| 118 | </label> |
| 119 | </span> |
| 120 | </li> |
| 121 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 122 | <span> |
| 123 | <a href="javascript:void(0);" class="btn btn-danger text-white" id="disconnect-btn"><i class="fa fa-power-off text-white"></i> Disconnect</a> |
| 124 | </span> |
| 125 | </li> |
| 126 | </ul> |
| 127 | <p class="mb-0 mt-2"><i class="fa fa-info-circle text-primary" aria-hidden="true"></i> You can further configure how NitroPack's optimization behaves through your account at <a href="https://nitropack.io/" target="_blank">https://nitropack.io/ <i class="fa fa-external-link"></i></a>.</p> |
| 128 | </div> |
| 129 | </div> |
| 130 | </div> |
| 131 | </div> |
| 132 | <div class="col-md-6 mb-3"> |
| 133 | <div class="card-overlay-blurrable np-widget" id="automations-widget"> |
| 134 | <div class="card card-d-item"> |
| 135 | <div class="card-body"> |
| 136 | <h5 class="card-title">Automated Behavior</h5> |
| 137 | <ul class="list-group list-group-flush"> |
| 138 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 139 | <span>Purge affected cache when content is updated or published</span> |
| 140 | <span id="auto-purge-toggle"> |
| 141 | <label id="auto-purge-status-slider" class="switch"> |
| 142 | <input type="checkbox" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>> |
| 143 | <span class="slider"></span> |
| 144 | </label> |
| 145 | </span> |
| 146 | </li> |
| 147 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center"> |
| 148 | <span>Select what post/page types get optimized</span> |
| 149 | <span id="cacheable-post-types-btn"> |
| 150 | <a href="javascript:void(0);" class="btn btn-light btn-outline-secondary" data-toggle="modal" data-target="#cacheable-post-types-modal"><i class="fa fa-cog"></i></a> |
| 151 | </span> |
| 152 | </li> |
| 153 | </ul> |
| 154 | </div> |
| 155 | </div> |
| 156 | </div> |
| 157 | </div> |
| 158 | </div> |
| 159 | </div> |
| 160 | |
| 161 | <!-- Post Types Modal --> |
| 162 | <div class="modal" id="cacheable-post-types-modal" tabindex="-1" role="dialog" aria-labelledby="cacheable-post-types-title" aria-hidden="true" data-backdrop="false"> |
| 163 | <div class="modal-dialog modal-dialog-centered" role="document"> |
| 164 | <div class="modal-content"> |
| 165 | <div class="modal-header"> |
| 166 | <h5 class="modal-title" id="cacheable-post-types-title">Configure page types that can be optimized</h5> |
| 167 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
| 168 | <span aria-hidden="true">×</span> |
| 169 | </button> |
| 170 | </div> |
| 171 | <div class="modal-body nitropack-scrollable-modal-body"> |
| 172 | <ul class="list-group list-group-flush"> |
| 173 | <?php foreach ($objectTypes as $objectType) {?> |
| 174 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center border-0"> |
| 175 | <span><?php echo $objectType->label; ?></span> |
| 176 | <span id="post-type-<?php echo $objectType->name; ?>-toggle"> |
| 177 | <label id="post-type-<?php echo $objectType->name; ?>-status-slider" class="switch"> |
| 178 | <input class="cacheable-post-type" name="<?php echo $objectType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($objectType->name, $cacheableObjectTypes)) echo 'checked'; ?>> |
| 179 | <span class="slider"></span> |
| 180 | </label> |
| 181 | </span> |
| 182 | </li> |
| 183 | <?php if (!empty($objectType->taxonomies)) {?> |
| 184 | <?php foreach ($objectType->taxonomies as $taxonomyType) {?> |
| 185 | <li class="list-group-item px-0 d-flex justify-content-between align-items-center list-group-item-indented border-0"> |
| 186 | <span><?php echo $taxonomyType->label; ?></span> |
| 187 | <span id="post-type-<?php echo $taxonomyType->name; ?>-toggle"> |
| 188 | <label id="post-type-<?php echo $taxonomyType->name; ?>-status-slider" class="switch"> |
| 189 | <input class="cacheable-post-type" name="<?php echo $taxonomyType->name; ?>" type="checkbox" id="post-type-post-status" <?php if (in_array($taxonomyType->name, $cacheableObjectTypes)) echo 'checked'; ?>> |
| 190 | <span class="slider"></span> |
| 191 | </label> |
| 192 | </span> |
| 193 | </li> |
| 194 | <?php }?> |
| 195 | <?php }?> |
| 196 | <?php }?> |
| 197 | </ul> |
| 198 | </div> |
| 199 | <div class="modal-footer"> |
| 200 | <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> |
| 201 | <button type="button" class="btn btn-primary" id="save-cacheable-post-types">Save changes <i class="fa fa-spinner fa-spin d-none"></i></button> |
| 202 | </div> |
| 203 | </div> |
| 204 | </div> |
| 205 | </div> |
| 206 | <script> |
| 207 | ($ => { |
| 208 | var getOptimizationsTimeout = null; |
| 209 | |
| 210 | $(window).on("load",function() { |
| 211 | $("#optimizations-widget").cardOverlay("loading", {message: "Loading optimizations data"}); |
| 212 | $("#plan-details-widget").cardOverlay("loading", {message: "Loading plan data"}); |
| 213 | $("#quicksetup-widget").cardOverlay("loading", {message: "Loading settings"}); |
| 214 | getOptimizations(); |
| 215 | getPlan(); |
| 216 | getQuickSetup(); |
| 217 | |
| 218 | <?php if ($checkedCompression != 1) { ?> |
| 219 | autoDetectCompression(); |
| 220 | <?php } ?> |
| 221 | }); |
| 222 | |
| 223 | $(document).on('click', '[data-hideable]', function(e) { |
| 224 | e.preventDefault(); |
| 225 | |
| 226 | $('[data-hideable]').removeClass('optimizations-hidden'); |
| 227 | |
| 228 | $(this).addClass('optimizations-hidden'); |
| 229 | }); |
| 230 | |
| 231 | $(document).on('click', '#optimizations-invalidate-cache', function(e) { |
| 232 | e.preventDefault(); |
| 233 | //Overlay.loading("Invalidating cache..."); |
| 234 | |
| 235 | invalidateEvent = new Event("cache.invalidate.request"); |
| 236 | window.dispatchEvent(invalidateEvent); |
| 237 | }); |
| 238 | |
| 239 | $(document).on('click', '#optimizations-purge-cache', function(e) { |
| 240 | e.preventDefault(); |
| 241 | //Overlay.loading("Purging cache..."); |
| 242 | |
| 243 | purgeEvent = new Event("cache.purge.request"); |
| 244 | window.dispatchEvent(purgeEvent); |
| 245 | }); |
| 246 | |
| 247 | $("#btn-run-warmup").on("click", function(e) { |
| 248 | runWarmup(); |
| 249 | }) |
| 250 | |
| 251 | $("#btn-stop-warmup").on("click", function(e) { |
| 252 | disableWarmup(); |
| 253 | }) |
| 254 | |
| 255 | var estimateWarmup = (id, retry) => { |
| 256 | id = id || null; |
| 257 | retry = retry || 0; |
| 258 | if (!id) { |
| 259 | $("#settings-widget").cardOverlay("loading", {message: "Estimating optimizations usage"}); |
| 260 | //$("#estimation-spinner").show(); |
| 261 | //$("#warmup-status-slider").hide(); |
| 262 | |
| 263 | $.post(ajaxurl, { |
| 264 | action: 'nitropack_estimate_warmup' |
| 265 | }, function(response) { |
| 266 | var resp = JSON.parse(response); |
| 267 | if (resp.type == "success") { |
| 268 | setTimeout( (function(id){ |
| 269 | estimateWarmup(id); |
| 270 | })(resp.res), 1000 ); |
| 271 | } else { |
| 272 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000}); |
| 273 | } |
| 274 | }); |
| 275 | } else { |
| 276 | $.post(ajaxurl, { |
| 277 | action: 'nitropack_estimate_warmup', |
| 278 | estId: id |
| 279 | }, function(response) { |
| 280 | var resp = JSON.parse(response); |
| 281 | if (resp.type == "success") { |
| 282 | if (isNaN(resp.res) || resp.res == -1) { // Still calculating |
| 283 | if (retry >= 10) { |
| 284 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed. Please try again or contact support if the issue persists.", dismissable: true}); |
| 285 | } else { |
| 286 | setTimeout( (function(id, retry){ |
| 287 | estimateWarmup(id, retry); |
| 288 | })(id, retry+1), 1000 ); |
| 289 | } |
| 290 | } else { |
| 291 | if (resp.res == 0) { |
| 292 | $("#settings-widget").cardOverlay("notify", {message: "We could not find any links for warming up on your home page", timeout: 3000}); |
| 293 | } else { |
| 294 | var confirmHtml = '<p>Enabling cache warmup will use ' + resp.res + ' page optimizations. Would you like to continue?</p>'; |
| 295 | confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm">Yes</p></a>'; |
| 296 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 297 | } |
| 298 | } |
| 299 | } else { |
| 300 | $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000}); |
| 301 | } |
| 302 | }); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | window.confirmWarmup = function() { |
| 307 | $("#settings-widget").cardOverlay("loading", {message: "Enabling warmup"}); |
| 308 | enableWarmup(); |
| 309 | } |
| 310 | |
| 311 | window.rejectWarmup = function() { |
| 312 | $("#settings-widget").cardOverlay("clear"); |
| 313 | } |
| 314 | |
| 315 | var enableWarmup = () => { |
| 316 | jQuery.post(ajaxurl, { |
| 317 | action: 'nitropack_enable_warmup' |
| 318 | }, function(response) { |
| 319 | var resp = JSON.parse(response); |
| 320 | if (resp.type == "success") { |
| 321 | $("#settings-widget").cardOverlay("clear"); |
| 322 | $("#warmup-status").attr("checked", true); |
| 323 | } else { |
| 324 | setTimeout(enableWarmup, 1000); |
| 325 | } |
| 326 | }); |
| 327 | } |
| 328 | |
| 329 | var disableWarmup = () => { |
| 330 | jQuery.post(ajaxurl, { |
| 331 | action: 'nitropack_disable_warmup' |
| 332 | }, function(response) { |
| 333 | var resp = JSON.parse(response); |
| 334 | if (resp.type == "success") { |
| 335 | // Success notification |
| 336 | } else { |
| 337 | // Error notification |
| 338 | } |
| 339 | }); |
| 340 | } |
| 341 | |
| 342 | var runWarmup = () => { |
| 343 | jQuery.post(ajaxurl, { |
| 344 | action: 'nitropack_run_warmup' |
| 345 | }, function(response) { |
| 346 | var resp = JSON.parse(response); |
| 347 | if (resp.type == "success") { |
| 348 | // Success notification |
| 349 | } else { |
| 350 | // Error notification |
| 351 | } |
| 352 | }); |
| 353 | } |
| 354 | |
| 355 | var getOptimizations = _ => { |
| 356 | $.ajax({ |
| 357 | url: '<?php echo $optimizationDetailsUrl; ?>', |
| 358 | type: 'GET', |
| 359 | dataType: 'json', |
| 360 | success: function(data) { |
| 361 | $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo); |
| 362 | if (data.last_cache_purge.reason) { |
| 363 | $('[data-purge-reason]').text(data.last_cache_purge.reason); |
| 364 | $('#last-cache-purge-reason').show(); |
| 365 | } else { |
| 366 | $('#last-cache-purge-reason').hide(); |
| 367 | } |
| 368 | |
| 369 | if (data.pending_count) { |
| 370 | $("#pending-optimizations-count").text(data.pending_count); |
| 371 | $("#pending-optimizations-section").show(); |
| 372 | } else { |
| 373 | $("#pending-optimizations-section").hide(); |
| 374 | } |
| 375 | |
| 376 | $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop); |
| 377 | $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile); |
| 378 | $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet); |
| 379 | $('[data-optimized-pages-total]').text(data.optimized_pages.total); |
| 380 | |
| 381 | $("#optimizations-widget").cardOverlay("clear"); |
| 382 | }, |
| 383 | error: function() { |
| 384 | //Overlay.error("An unexpected error has occurred.", 10000, true); |
| 385 | }, |
| 386 | complete: function() { |
| 387 | if (!getOptimizationsTimeout) { |
| 388 | getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 10000); |
| 389 | } |
| 390 | } |
| 391 | }) |
| 392 | } |
| 393 | |
| 394 | var getPlan = _ => { |
| 395 | $.ajax({ |
| 396 | url: '<?php echo $planDetailsUrl; ?>', |
| 397 | type: 'GET', |
| 398 | dataType: 'json', |
| 399 | success: function(data) { |
| 400 | $('[data-plan-title]').text(data.plan_title); |
| 401 | $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A'); |
| 402 | $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A'); |
| 403 | |
| 404 | for (prop in data) { |
| 405 | if (prop.indexOf("show_") === 0) continue; |
| 406 | if (prop.indexOf("label_") === 0) continue; |
| 407 | if (prop.indexOf("max_") === 0) continue; |
| 408 | if ( |
| 409 | typeof data["show_" + prop] != "undefined" && |
| 410 | data["show_" + prop] && |
| 411 | typeof data["label_" + prop] != "undefined" && |
| 412 | typeof data["max_" + prop] != "undefined" |
| 413 | ) { |
| 414 | let propertyLabel = data["label_" + prop]; |
| 415 | let propertyValue = data[prop]; |
| 416 | let propertyLimit = data["max_" + prop]; |
| 417 | $("#plan-quotas").append('<li class="list-group-item px-0 d-flex justify-content-between align-items-center">' + propertyLabel + ' <span><span data-optimizations>' + propertyValue + '</span> out of <span data-max-optimizations>' + propertyLimit + '</span></span></li>'); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | $("#plan-details-widget").cardOverlay("clear"); |
| 422 | }, |
| 423 | error: function() { |
| 424 | $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching plan data"}); |
| 425 | } |
| 426 | }) |
| 427 | } |
| 428 | |
| 429 | var getQuickSetup = _ => { |
| 430 | $.ajax({ |
| 431 | url: '<?php echo $quickSetupUrl; ?>', |
| 432 | type: 'GET', |
| 433 | dataType: 'json', |
| 434 | success: function(data) { |
| 435 | $('#range').val(data.optimization_level); |
| 436 | $('#manual-settings-url').attr('href', data.manual_settings_url); |
| 437 | |
| 438 | document.getElementById('range').oninput(false); |
| 439 | $("#quicksetup-widget").cardOverlay("clear"); |
| 440 | }, |
| 441 | error: function() { |
| 442 | $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching the optimization level settings"}); |
| 443 | } |
| 444 | }) |
| 445 | } |
| 446 | |
| 447 | window.addEventListener("cache.invalidate.success", getOptimizations); |
| 448 | window.addEventListener("cache.purge.success", getOptimizations); |
| 449 | |
| 450 | |
| 451 | var autoDetectCompression = function() { |
| 452 | $("#settings-widget").cardOverlay("loading", {message: "Testing current compression status"}); |
| 453 | |
| 454 | $.post(ajaxurl, { |
| 455 | action: 'nitropack_test_compression_ajax' |
| 456 | }, function(response) { |
| 457 | var resp = JSON.parse(response); |
| 458 | if (resp.status == "success") { |
| 459 | if (resp.hasCompression) { // compression already enabled |
| 460 | $("#compression-status").attr("checked", false); |
| 461 | $("#settings-widget").cardOverlay("success", {message: "Compression is already enabled on your server! There is no need to enable it in NitroPack.", timeout: 3000}); |
| 462 | } else { // no compression - enable ours |
| 463 | $("#compression-status").attr("checked", true); |
| 464 | $("#settings-widget").cardOverlay("success", {message: "No compression was detected! We will now enable it in NitroPack.", timeout: 3000}); |
| 465 | } |
| 466 | Notification.success('Compression settings saved'); |
| 467 | } else { |
| 468 | $("#settings-widget").cardOverlay("error", {message: "Could not determine compression status automatically. Please configure it manually.", timeout: 3000}); |
| 469 | } |
| 470 | }); |
| 471 | } |
| 472 | |
| 473 | $("#compression-status").on("click", function(e) { |
| 474 | $.post(ajaxurl, { |
| 475 | action: 'nitropack_set_compression_ajax', |
| 476 | data: { |
| 477 | compressionStatus: $(this).is(":checked") ? 1 : 0 |
| 478 | } |
| 479 | }, function(response) { |
| 480 | Notification.success('Compression settings saved'); |
| 481 | }); |
| 482 | }); |
| 483 | |
| 484 | $("#auto-purge-status").on("click", function(e) { |
| 485 | $.post(ajaxurl, { |
| 486 | action: 'nitropack_set_auto_cache_purge_ajax', |
| 487 | autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0 |
| 488 | }, function(response) { |
| 489 | Notification.success('Automatic cache purge settings saved'); |
| 490 | }); |
| 491 | }); |
| 492 | |
| 493 | $("#save-cacheable-post-types").on("click", function(e) { |
| 494 | $(this).find("i").removeClass("d-none"); |
| 495 | $.ajax({ |
| 496 | url: ajaxurl, |
| 497 | type: "POST", |
| 498 | data: { |
| 499 | action: 'nitropack_set_cacheable_post_types', |
| 500 | cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray() |
| 501 | }, |
| 502 | success: function() { |
| 503 | Notification.success('Changes saved'); |
| 504 | }, |
| 505 | error: function() { |
| 506 | Notification.error('There was an error while saving the changes. Please try again.'); |
| 507 | }, |
| 508 | complete: function() { |
| 509 | $("#save-cacheable-post-types i").addClass("d-none"); |
| 510 | $("#cacheable-post-types-modal").modal("hide"); |
| 511 | } |
| 512 | }); |
| 513 | }); |
| 514 | |
| 515 | $(document).on('click', "#compression-test-btn", e => { |
| 516 | e.preventDefault(); |
| 517 | |
| 518 | autoDetectCompression(); |
| 519 | }); |
| 520 | |
| 521 | window.confirmDisconnect = function() { |
| 522 | $("#settings-widget").cardOverlay("loading", {message: "Disconnecting..."}); |
| 523 | $.ajax({ |
| 524 | url: ajaxurl, |
| 525 | type: "POST", |
| 526 | data: { |
| 527 | action: "nitropack_disconnect" |
| 528 | }, |
| 529 | complete: function() { |
| 530 | location.reload(); |
| 531 | } |
| 532 | }); |
| 533 | } |
| 534 | |
| 535 | window.rejectDisconnect = function() { |
| 536 | $("#settings-widget").cardOverlay("clear"); |
| 537 | } |
| 538 | |
| 539 | $(document).on('click', "#disconnect-btn", e => { |
| 540 | e.preventDefault(); |
| 541 | |
| 542 | var confirmHtml = '<p>This will disconnect the plugin and NitroPack.io will stop working. Are you sure that you wish to continue?</p>'; |
| 543 | confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-success btn-sm">Yes</p></a>'; |
| 544 | $("#settings-widget").cardOverlay("notify", {message: confirmHtml}); |
| 545 | }); |
| 546 | |
| 547 | $("#warmup-status-slider").on("click", function(e) { |
| 548 | e.preventDefault(); |
| 549 | var isEnabled = $("#warmup-status").is(":checked"); |
| 550 | if (isEnabled) { |
| 551 | disableWarmup(); |
| 552 | $("#warmup-status").attr("checked", false); |
| 553 | } else { |
| 554 | estimateWarmup(); |
| 555 | } |
| 556 | }); |
| 557 | |
| 558 | var loadWarmupStatus = function() { |
| 559 | $.ajax({ |
| 560 | url: ajaxurl, |
| 561 | type: "POST", |
| 562 | data: { |
| 563 | action: "nitropack_warmup_stats" |
| 564 | }, |
| 565 | dataType: "json", |
| 566 | success: function(resp) { |
| 567 | if (resp.type == "success") { |
| 568 | $("#warmup-status").attr("checked", !!resp.stats.status); |
| 569 | $("#loading-warmup-status").hide(); |
| 570 | $("#warmup-toggle").show(); |
| 571 | } else { |
| 572 | setTimeout(loadWarmupStatus, 500); |
| 573 | } |
| 574 | } |
| 575 | }); |
| 576 | } |
| 577 | loadWarmupStatus(); |
| 578 | })(jQuery); |
| 579 | |
| 580 | (_ => { |
| 581 | const classIndex = { |
| 582 | 1: 'range-success', |
| 583 | 2: 'range-warning', |
| 584 | 3: 'range-danger', |
| 585 | 4: 'range-ludicrous', |
| 586 | 5: 'range-manual', |
| 587 | } |
| 588 | |
| 589 | const atTimeout = (_ => { |
| 590 | var timeout; |
| 591 | |
| 592 | return (callback, time) => { |
| 593 | clearTimeout(timeout); |
| 594 | timeout = setTimeout(callback, time) |
| 595 | }; |
| 596 | })(); |
| 597 | |
| 598 | const saveSetting = function(value) { |
| 599 | return new Promise((resolve, reject) => { |
| 600 | var xhr = new XMLHttpRequest(); |
| 601 | |
| 602 | xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true); |
| 603 | |
| 604 | //Send the proper header information along with the request |
| 605 | xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
| 606 | |
| 607 | xhr.onreadystatechange = function() { // Call a function when the state changes. |
| 608 | if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { |
| 609 | resolve(); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | xhr.send("setting=" + value); |
| 614 | }); |
| 615 | } |
| 616 | |
| 617 | document.getElementById('range').oninput = function() { |
| 618 | var children = document.getElementById('description').children; |
| 619 | var shown = parseInt(this.value); |
| 620 | |
| 621 | for (var i = 0; i < children.length; i++) { |
| 622 | children.item(i).classList.toggle('hidden', i != shown); |
| 623 | } |
| 624 | |
| 625 | document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual'); |
| 626 | |
| 627 | if (classIndex[shown]) { |
| 628 | document.getElementById('range').classList.add(classIndex[shown]); |
| 629 | } |
| 630 | |
| 631 | atTimeout(async function() { |
| 632 | await saveSetting(shown); |
| 633 | }, 500); |
| 634 | }; |
| 635 | |
| 636 | var min = parseInt(document.getElementById('range').min); |
| 637 | var max = parseInt(document.getElementById('range').max); |
| 638 | for (var i = min; i <= max; i++) { |
| 639 | let divisor = document.createElement('div'); |
| 640 | divisor.classList.add("divisor"); |
| 641 | document.getElementById('divisors').appendChild(divisor); |
| 642 | |
| 643 | let label = document.createElement('div'); |
| 644 | label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent; |
| 645 | label.classList.add("label"); |
| 646 | document.getElementById('labels').appendChild(label); |
| 647 | } |
| 648 | })(); |
| 649 | </script> |
| 650 |