PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.5.5
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.5.5
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / view / dashboard.php
nitropack / view Last commit date
images 5 years ago javascript 4 years ago stylesheet 4 years ago admin.php 4 years ago connect.php 5 years ago dashboard.php 4 years ago diag.php 4 years ago help.php 6 years ago safemode.tpl 4 years ago
dashboard.php
786 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&nbsp;&nbsp;<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 <i id="np-purge-cache-loading"class="fa fa-refresh fa-spin" style="margin:5px;font-size:48px;display:none;"></i>
25 <i id="np-purge-cache-success" class="fa fa-check-circle" style="margin:5px;font-size:48px;display:none;"></i>
26 <i id="np-purge-cache-error" class="fa fa-times-circle" style="margin:5px;font-size:48px;display:none;"></i>
27 <button id="optimizations-purge-cache" class="btn btn-light btn-outline-secondary btn-widget-optimizations">Purge Cache</button>
28 </div>
29 </div>
30 </div>
31 </div>
32 </div>
33 <div class="col-md-6 mb-3">
34 <div class="card-overlay-blurrable np-widget" id="plan-details-widget">
35 <div class="card card-d-item">
36 <div class="card-body">
37 <h5 class="card-title">Plan</h5>
38 <div class="mt-3">
39 <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>
40 </div>
41 <ul class="list-group list-group-flush" id="plan-quotas">
42 <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>
43 <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>
44 </ul>
45 <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>
46 </div>
47 </div>
48 </div>
49 </div>
50 <div class="col-md-6 mb-3">
51 <div class="card-overlay-blurrable np-widget" id="quicksetup-widget">
52 <div class="card card-d-item">
53 <div class="card-body">
54 <h5 class="card-title">Optimization Mode</h5>
55 <p><small>Slide to change your settings. This will update the level of optimization.</small></p>
56
57 <div id="range-container">
58 <div id="labels"></div>
59 <div id="range-element">
60 <div id="divisors"></div>
61 <input id="range" type="range" min="1" max="5" step="1" value="0" />
62 </div>
63 </div>
64
65 <div id="description">
66 <div class="text dummy">
67 <h6 class="text-success">Dummy</h6>
68 <p><small></small></p>
69 </div>
70 <div class="text standard">
71 <h6 class="text-info">Standard</h6>
72 <p><small>A pre-defined configuration without much regard for a high score. Enough to get you up and running.</small></p>
73 </div>
74 <div class="text medium">
75 <h6 class="text-success">Medium</h6>
76 <p><small>Well-balanced and suitable for most cases.</small></p>
77 </div>
78 <div class="text strong">
79 <h6 class="text-warning">Strong</h6>
80 <p><small>Includes advanced features like automatic image lazy loading and font definition modification. May cause issues in some cases.</small></p>
81 </div>
82 <div class="text ludicrous">
83 <h6 class="text-danger">Ludicrous</h6>
84 <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>
85 </div>
86 <div class="text custom">
87 <h6>Manual</h6>
88 <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>
89 </div>
90 </div>
91 </div>
92 </div>
93 </div>
94 </div>
95 <div class="col-md-6 mb-3">
96 <div class="card-overlay-blurrable np-widget" id="settings-widget">
97 <div class="card card-d-item">
98 <div class="card-body">
99 <h5 class="card-title">Settings</h5>
100 <ul class="list-group list-group-flush">
101 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
102 <span>Cache Warmup</br>
103 <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener">here</a></small>
104 </span>
105 <span id="loading-warmup-status">
106 Loading cache warmup status&nbsp;&nbsp;<i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
107 </span>
108 <span id="warmup-toggle" style="display: none;">
109 <label id="warmup-status-slider" class="switch">
110 <input type="checkbox" id="warmup-status">
111 <span class="slider"></span>
112 </label>
113 </span>
114 </li>
115 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
116 <span>Safe Mode</br>
117 <small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener">here</a></small>
118 </span>
119 <span id="loading-safemode-status">
120 Loading safe mode status&nbsp;&nbsp;<i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
121 </span>
122 <span id="safemode-toggle" style="display: none;">
123 <label id="safemode-status-slider" class="switch">
124 <input type="checkbox" id="safemode-status">
125 <span class="slider"></span>
126 </label>
127 </span>
128 </li>
129 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
130 <span id="detecting-compression" style="display: none;">Testing current compression status&nbsp;&nbsp;<a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span>
131 <span id="detected-compression">HTML Compression&nbsp;&nbsp;<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>
132 <span>
133 <label class="switch">
134 <input type="checkbox" id="compression-status" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>>
135 <span class="slider"></span>
136 </label>
137 </span>
138 </li>
139 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
140 <span>
141 <a href="javascript:void(0);" class="btn btn-danger text-white" id="disconnect-btn"><i class="fa fa-power-off text-white"></i>&nbsp;&nbsp;Disconnect</a>
142 </span>
143 </li>
144 </ul>
145 <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/&nbsp;&nbsp;<i class="fa fa-external-link"></i></a>.</p>
146 </div>
147 </div>
148 </div>
149 </div>
150 <div class="col-md-6 mb-3">
151 <div class="card-overlay-blurrable np-widget" id="automations-widget">
152 <div class="card card-d-item">
153 <div class="card-body">
154 <h5 class="card-title">Automated Behavior</h5>
155 <ul class="list-group list-group-flush">
156 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
157 <span>Purge affected cache when content is updated or published</span>
158 <span id="auto-purge-toggle">
159 <label id="auto-purge-status-slider" class="switch">
160 <input type="checkbox" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>>
161 <span class="slider"></span>
162 </label>
163 </span>
164 </li>
165 <?php if (\NitroPack\Integration\Plugin\BeaverBuilder::isActive()) { ?>
166 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
167 <span>Purge NitroPack cache when Beaver Builder cache is purged<br/>
168 <small>Warning: This will perform a full NitroPack cache purge</small>
169 </span>
170 <span id="bb-purge-toggle">
171 <label id="bb-purge-status-slider" class="switch">
172 <input type="checkbox" id="bb-purge-status" <?php if ($bbCacheSyncPurge) echo "checked"; ?>>
173 <span class="slider"></span>
174 </label>
175 </span>
176 </li>
177 <?php } ?>
178 <li class="list-group-item px-0 d-flex justify-content-between align-items-center">
179 <span>Select what post/page types get optimized</span>
180 <span id="cacheable-post-types-btn">
181 <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>
182 </span>
183 </li>
184 </ul>
185 </div>
186 </div>
187 </div>
188 </div>
189 </div>
190 </div>
191
192 <!-- Post Types Modal -->
193 <div class="modal" id="cacheable-post-types-modal" tabindex="-1" role="dialog" aria-labelledby="cacheable-post-types-title" aria-hidden="true" data-backdrop="false">
194 <div class="modal-dialog modal-dialog-centered" role="document">
195 <div class="modal-content">
196 <div class="modal-header">
197 <h5 class="modal-title" id="cacheable-post-types-title">Configure page types that can be optimized</h5>
198 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
199 <span aria-hidden="true">&times;</span>
200 </button>
201 </div>
202 <div class="modal-body nitropack-scrollable-modal-body">
203 <ul class="list-group list-group-flush">
204 <?php foreach ($objectTypes as $objectType) {?>
205 <li class="list-group-item px-0 d-flex justify-content-between align-items-center border-0">
206 <span><?php echo $objectType->label; ?></span>
207 <span id="post-type-<?php echo $objectType->name; ?>-toggle">
208 <label id="post-type-<?php echo $objectType->name; ?>-status-slider" class="switch">
209 <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'; ?>>
210 <span class="slider"></span>
211 </label>
212 </span>
213 </li>
214 <?php if (!empty($objectType->taxonomies)) {?>
215 <?php foreach ($objectType->taxonomies as $taxonomyType) {?>
216 <li class="list-group-item px-0 d-flex justify-content-between align-items-center list-group-item-indented border-0">
217 <span><?php echo $taxonomyType->label; ?></span>
218 <span id="post-type-<?php echo $taxonomyType->name; ?>-toggle">
219 <label id="post-type-<?php echo $taxonomyType->name; ?>-status-slider" class="switch">
220 <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'; ?>>
221 <span class="slider"></span>
222 </label>
223 </span>
224 </li>
225 <?php }?>
226 <?php }?>
227 <?php }?>
228 </ul>
229 </div>
230 <div class="modal-footer">
231 <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
232 <button type="button" class="btn btn-primary" id="save-cacheable-post-types">Save changes&nbsp;&nbsp;<i class="fa fa-spinner fa-spin d-none"></i></button>
233 </div>
234 </div>
235 </div>
236 </div>
237 <script>
238 ($ => {
239 var getOptimizationsTimeout = null;
240 let isClearing = false;
241
242 $(window).on("load",function() {
243 $("#optimizations-widget").cardOverlay("loading", {message: "Loading optimizations data"});
244 $("#plan-details-widget").cardOverlay("loading", {message: "Loading plan data"});
245 $("#quicksetup-widget").cardOverlay("loading", {message: "Loading settings"});
246 getOptimizations();
247 getPlan();
248 getQuickSetup();
249
250 <?php if ($checkedCompression != 1) { ?>
251 autoDetectCompression();
252 <?php } ?>
253 });
254
255 $(document).on('click', '[data-hideable]', function(e) {
256 e.preventDefault();
257
258 $('[data-hideable]').removeClass('optimizations-hidden');
259
260 $(this).addClass('optimizations-hidden');
261 });
262
263 $(document).on('click', '#optimizations-invalidate-cache', function(e) {
264 e.preventDefault();
265 //Overlay.loading("Invalidating cache...");
266
267 invalidateEvent = new Event("cache.invalidate.request");
268 window.dispatchEvent(invalidateEvent);
269 });
270
271 $(document).on('click', '#optimizations-purge-cache', function(e) {
272 e.preventDefault();
273 //Overlay.loading("Purging cache...");
274 purgeEvent = new Event("cache.purge.request");
275 window.dispatchEvent(purgeEvent);
276 });
277
278 $(document).on('click', '[nitropack-rc-data]', function(e) {
279 e.preventDefault();
280 if (isClearing) return;
281 let currentButton = $(this);
282 $.ajax({
283 url: ajaxurl,
284 type: "POST",
285 dataType: "text",
286 data: {
287 action: 'nitropack_clear_residual_cache',
288 gde: currentButton.attr('nitropack-rc-data')
289 },
290 beforeSend: function () {
291 currentButton.parent(".alert-warning").hide();
292 isClearing = true;
293 },
294 success: function(resp) {
295 result = JSON.parse(resp);
296 Notification[result.type](result.message);
297 },
298 error: function(resp) {
299 result = JSON.parse(resp);
300 Notification[result.type](result.message);
301 },
302 complete: function() {
303 isClearing = false;
304 setTimeout(function(){location.reload();}, 3000);
305 }
306 });
307 });
308
309 $("#btn-run-warmup").on("click", function(e) {
310 runWarmup();
311 })
312
313 $("#btn-stop-warmup").on("click", function(e) {
314 disableWarmup();
315 })
316
317 var estimateWarmup = (id, retry) => {
318 id = id || null;
319 retry = retry || 0;
320 if (!id) {
321 $("#settings-widget").cardOverlay("loading", {message: "Estimating optimizations usage"});
322 //$("#estimation-spinner").show();
323 //$("#warmup-status-slider").hide();
324
325 $.post(ajaxurl, {
326 action: 'nitropack_estimate_warmup'
327 }, function(response) {
328 var resp = JSON.parse(response);
329 if (resp.type == "success") {
330 setTimeout( (function(id){
331 estimateWarmup(id);
332 })(resp.res), 1000 );
333 } else {
334 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000});
335 }
336 });
337 } else {
338 $.post(ajaxurl, {
339 action: 'nitropack_estimate_warmup',
340 estId: id
341 }, function(response) {
342 var resp = JSON.parse(response);
343 if (resp.type == "success") {
344 if (isNaN(resp.res) || resp.res == -1) { // Still calculating
345 if (retry >= 10) {
346 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed. Please try again or contact support if the issue persists.", dismissable: true});
347 } else {
348 setTimeout( (function(id, retry){
349 estimateWarmup(id, retry);
350 })(id, retry+1), 1000 );
351 }
352 } else {
353 if (resp.res == 0) {
354 $("#settings-widget").cardOverlay("notify", {message: "We could not find any links for warming up on your home page", timeout: 3000});
355 } else {
356 var confirmHtml = '<p>Enabling cache warmup will use ' + resp.res + ' page optimizations. Would you like to continue?</p>';
357 confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectWarmup()" class="btn btn-default btn-sm">No</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="confirmWarmup()" class="btn btn-success btn-sm">Yes</p></a>';
358 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
359 }
360 }
361 } else {
362 $("#settings-widget").cardOverlay("error", {message: "Warmup estimation failed", timeout: 3000});
363 }
364 });
365 }
366 }
367
368 window.confirmWarmup = function() {
369 $("#settings-widget").cardOverlay("loading", {message: "Enabling warmup"});
370 enableWarmup();
371 }
372
373 window.rejectWarmup = function() {
374 $("#settings-widget").cardOverlay("clear");
375 }
376
377 var enableWarmup = () => {
378 jQuery.post(ajaxurl, {
379 action: 'nitropack_enable_warmup'
380 }, function(response) {
381 var resp = JSON.parse(response);
382 if (resp.type == "success") {
383 $("#settings-widget").cardOverlay("clear");
384 $("#warmup-status").attr("checked", true);
385 } else {
386 setTimeout(enableWarmup, 1000);
387 }
388 });
389 }
390
391 var disableWarmup = () => {
392 jQuery.post(ajaxurl, {
393 action: 'nitropack_disable_warmup'
394 }, function(response) {
395 var resp = JSON.parse(response);
396 if (resp.type == "success") {
397 // Success notification
398 } else {
399 // Error notification
400 }
401 });
402 }
403
404 var runWarmup = () => {
405 jQuery.post(ajaxurl, {
406 action: 'nitropack_run_warmup'
407 }, function(response) {
408 var resp = JSON.parse(response);
409 if (resp.type == "success") {
410 // Success notification
411 } else {
412 // Error notification
413 }
414 });
415 }
416
417 var enableSafemode = () => {
418 jQuery.post(ajaxurl, {
419 action: 'nitropack_enable_safemode'
420 }, function(response) {
421 var resp = JSON.parse(response);
422 if (resp.type == "success") {
423 $("#safemode-status").attr("checked", true);
424 // Success notification
425 } else {
426 $("#safemode-status").attr("checked", false);
427 // Error notification
428 }
429 });
430 }
431
432 var disableSafemode = () => {
433 jQuery.post(ajaxurl, {
434 action: 'nitropack_disable_safemode'
435 }, function(response) {
436 var resp = JSON.parse(response);
437 if (resp.type == "success") {
438 // Success notification
439 } else {
440 // Error notification
441 }
442 });
443 }
444
445 var getOptimizations = _ => {
446 $.ajax({
447 url: '<?php echo $optimizationDetailsUrl; ?>',
448 type: 'GET',
449 dataType: 'json',
450 success: function(data) {
451 $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo);
452 if (data.last_cache_purge.reason) {
453 $('[data-purge-reason]').text(data.last_cache_purge.reason);
454 $('#last-cache-purge-reason').show();
455 } else {
456 $('#last-cache-purge-reason').hide();
457 }
458
459 if (data.pending_count) {
460 $("#pending-optimizations-count").text(data.pending_count);
461 $("#pending-optimizations-section").show();
462 } else {
463 $("#pending-optimizations-section").hide();
464 }
465
466 $('[data-optimized-pages-desktop]').text(data.optimized_pages.desktop);
467 $('[data-optimized-pages-mobile]').text(data.optimized_pages.mobile);
468 $('[data-optimized-pages-tablet]').text(data.optimized_pages.tablet);
469 $('[data-optimized-pages-total]').text(data.optimized_pages.total);
470
471 $("#optimizations-widget").cardOverlay("clear");
472 },
473 error: function() {
474 //Overlay.error("An unexpected error has occurred.", 10000, true);
475 },
476 complete: function() {
477 if (!getOptimizationsTimeout) {
478 getOptimizationsTimeout = setTimeout(function() {getOptimizationsTimeout = null; getOptimizations();}, 60000);
479 }
480 }
481 })
482 }
483
484 var getPlan = _ => {
485 $.ajax({
486 url: '<?php echo $planDetailsUrl; ?>',
487 type: 'GET',
488 dataType: 'json',
489 success: function(data) {
490 $('[data-plan-title]').text(data.plan_title);
491 $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A');
492 $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A');
493
494 for (prop in data) {
495 if (prop.indexOf("show_") === 0) continue;
496 if (prop.indexOf("label_") === 0) continue;
497 if (prop.indexOf("max_") === 0) continue;
498 if (
499 typeof data["show_" + prop] != "undefined" &&
500 data["show_" + prop] &&
501 typeof data["label_" + prop] != "undefined" &&
502 typeof data["max_" + prop] != "undefined"
503 ) {
504 let propertyLabel = data["label_" + prop];
505 let propertyValue = data[prop];
506 let propertyLimit = data["max_" + prop];
507 $("#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>');
508 }
509 }
510
511 $("#plan-details-widget").cardOverlay("clear");
512 },
513 error: function() {
514 $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching plan data"});
515 }
516 })
517 }
518
519 var getQuickSetup = _ => {
520 $.ajax({
521 url: '<?php echo $quickSetupUrl; ?>',
522 type: 'GET',
523 dataType: 'json',
524 success: function(data) {
525 $('#range').val(data.optimization_level);
526 $('#manual-settings-url').attr('href', data.manual_settings_url);
527
528 document.getElementById('range').oninput(false);
529 $("#quicksetup-widget").cardOverlay("clear");
530 },
531 error: function() {
532 $("#plan-details-widget").cardOverlay("error", {message: "Error while fetching the optimization level settings"});
533 }
534 })
535 }
536
537 window.addEventListener("cache.invalidate.success", getOptimizations);
538 if ($('#np-onstate-cache-purge').length) {
539 window.addEventListener("cache.purge.success", function(){setTimeout(function(){document.cookie = "nitropack_apwarning=1; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=<?php echo nitropack_cookiepath(); ?>"; window.location.reload()}, 1500)});
540 } else {
541 window.addEventListener("cache.purge.success", getOptimizations);
542 }
543
544
545 var autoDetectCompression = function() {
546 $("#settings-widget").cardOverlay("loading", {message: "Testing current compression status"});
547
548 $.post(ajaxurl, {
549 action: 'nitropack_test_compression_ajax'
550 }, function(response) {
551 var resp = JSON.parse(response);
552 if (resp.status == "success") {
553 if (resp.hasCompression) { // compression already enabled
554 $("#compression-status").attr("checked", false);
555 $("#settings-widget").cardOverlay("success", {message: "Compression is already enabled on your server! There is no need to enable it in NitroPack.", timeout: 3000});
556 } else { // no compression - enable ours
557 $("#compression-status").attr("checked", true);
558 $("#settings-widget").cardOverlay("success", {message: "No compression was detected! We will now enable it in NitroPack.", timeout: 3000});
559 }
560 Notification.success('Compression settings saved');
561 } else {
562 $("#settings-widget").cardOverlay("error", {message: "Could not determine compression status automatically. Please configure it manually.", timeout: 3000});
563 }
564 });
565 }
566
567 $("#compression-status").on("click", function(e) {
568 $.post(ajaxurl, {
569 action: 'nitropack_set_compression_ajax',
570 data: {
571 compressionStatus: $(this).is(":checked") ? 1 : 0
572 }
573 }, function(response) {
574 Notification.success('Compression settings saved');
575 });
576 });
577
578 $("#auto-purge-status").on("click", function(e) {
579 $.post(ajaxurl, {
580 action: 'nitropack_set_auto_cache_purge_ajax',
581 autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0
582 }, function(response) {
583 Notification.success('Automatic cache purge settings saved');
584 });
585 });
586
587 $("#bb-purge-status").on("click", function(e) {
588 $.post(ajaxurl, {
589 action: 'nitropack_set_bb_cache_purge_sync_ajax',
590 bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0
591 }, function(response) {
592 Notification.success('Beaver Builder cache purge sync settings are saved.');
593 });
594 });
595
596 $("#save-cacheable-post-types").on("click", function(e) {
597 $(this).find("i").removeClass("d-none");
598 $.ajax({
599 url: ajaxurl,
600 type: "POST",
601 data: {
602 action: 'nitropack_set_cacheable_post_types',
603 cacheableObjectTypes: $('.cacheable-post-type:checked').map(function(i, el){ return el.name; }).toArray()
604 },
605 success: function() {
606 Notification.success('Changes saved');
607 },
608 error: function() {
609 Notification.error('There was an error while saving the changes. Please try again.');
610 },
611 complete: function() {
612 $("#save-cacheable-post-types i").addClass("d-none");
613 $("#cacheable-post-types-modal").modal("hide");
614 }
615 });
616 });
617
618 $(document).on('click', "#compression-test-btn", e => {
619 e.preventDefault();
620
621 autoDetectCompression();
622 });
623
624 window.confirmDisconnect = function() {
625 $("#settings-widget").cardOverlay("loading", {message: "Disconnecting..."});
626 $.ajax({
627 url: ajaxurl,
628 type: "POST",
629 data: {
630 action: "nitropack_disconnect"
631 },
632 complete: function() {
633 location.reload();
634 }
635 });
636 }
637
638 window.rejectDisconnect = function() {
639 $("#settings-widget").cardOverlay("clear");
640 }
641
642 $(document).on('click', "#disconnect-btn", e => {
643 e.preventDefault();
644
645 var confirmHtml = '<p>Are you sure that you wish to disconnect?</p>';
646 confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-info btn-sm">Disconnect</a></p>';
647 $("#settings-widget").cardOverlay("notify", {message: confirmHtml});
648 });
649
650 $("#warmup-status-slider").on("click", function(e) {
651 e.preventDefault();
652 var isEnabled = $("#warmup-status").is(":checked");
653 if (isEnabled) {
654 disableWarmup();
655 $("#warmup-status").attr("checked", false);
656 } else {
657 estimateWarmup();
658 }
659 });
660
661 var loadWarmupStatus = function() {
662 $.ajax({
663 url: ajaxurl,
664 type: "POST",
665 data: {
666 action: "nitropack_warmup_stats"
667 },
668 dataType: "json",
669 success: function(resp) {
670 if (resp.type == "success") {
671 $("#warmup-status").attr("checked", !!resp.stats.status);
672 $("#loading-warmup-status").hide();
673 $("#warmup-toggle").show();
674 } else {
675 setTimeout(loadWarmupStatus, 500);
676 }
677 }
678 });
679 }
680 loadWarmupStatus();
681
682 $("#safemode-status-slider").on("click", function(e) {
683 e.preventDefault();
684 var isEnabled = $("#safemode-status").is(":checked");
685 if (isEnabled) {
686 disableSafemode();
687 $("#safemode-status").attr("checked", false);
688 } else {
689 enableSafemode();
690 $("#safemode-status").attr("checked", true);
691 }
692 });
693
694 var loadSafemodeStatus = function() {
695 $.ajax({
696 url: ajaxurl,
697 type: "POST",
698 data: {
699 action: "nitropack_safemode_status"
700 },
701 dataType: "json",
702 success: function(resp) {
703 if (resp.type == "success") {
704 $("#safemode-status").attr("checked", !!resp.isEnabled);
705 $("#loading-safemode-status").hide();
706 $("#safemode-toggle").show();
707 } else {
708 setTimeout(loadSafemodeStatus, 500);
709 }
710 }
711 });
712 }
713 loadSafemodeStatus();
714 })(jQuery);
715
716 (_ => {
717 const classIndex = {
718 1: 'range-success',
719 2: 'range-warning',
720 3: 'range-danger',
721 4: 'range-ludicrous',
722 5: 'range-manual',
723 }
724
725 const atTimeout = (_ => {
726 var timeout;
727
728 return (callback, time) => {
729 clearTimeout(timeout);
730 timeout = setTimeout(callback, time)
731 };
732 })();
733
734 const saveSetting = function(value) {
735 return new Promise((resolve, reject) => {
736 var xhr = new XMLHttpRequest();
737
738 xhr.open("POST", '<?php echo $quickSetupSaveUrl; ?>', true);
739
740 //Send the proper header information along with the request
741 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
742
743 xhr.onreadystatechange = function() { // Call a function when the state changes.
744 if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
745 resolve();
746 }
747 }
748
749 xhr.send("setting=" + value);
750 });
751 }
752
753 document.getElementById('range').oninput = function() {
754 var children = document.getElementById('description').children;
755 var shown = parseInt(this.value);
756
757 for (var i = 0; i < children.length; i++) {
758 children.item(i).classList.toggle('hidden', i != shown);
759 }
760
761 document.getElementById('range').classList.remove('range-success', 'range-warning', 'range-danger', 'range-ludicrous', 'range-manual');
762
763 if (classIndex[shown]) {
764 document.getElementById('range').classList.add(classIndex[shown]);
765 }
766
767 atTimeout(async function() {
768 await saveSetting(shown);
769 }, 500);
770 };
771
772 var min = parseInt(document.getElementById('range').min);
773 var max = parseInt(document.getElementById('range').max);
774 for (var i = min; i <= max; i++) {
775 let divisor = document.createElement('div');
776 divisor.classList.add("divisor");
777 document.getElementById('divisors').appendChild(divisor);
778
779 let label = document.createElement('div');
780 label.textContent = document.getElementById('description').children.item(i).getElementsByTagName('h6').item(0).textContent;
781 label.classList.add("label");
782 document.getElementById('labels').appendChild(label);
783 }
784 })();
785 </script>
786