PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 2.1.2
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v2.1.2
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / assets / js / admin / modules / modal.js

modal.js in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 2.1.2, at assets/js/admin/modules/modal.js

89 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global jQuery, PoweredCache, ajaxurl */
2 const { __ } = wp.i18n;
3
4 (function ($) {
5 // Use strict mode
6
7 // Define global PoweredCache object if it does not exist
8 if (typeof window.PoweredCache !== 'object') {
9 window.PoweredCache = {};
10 }
11
12 PoweredCache.pageModals = function () {
13 const body = $('body');
14 if (!body.hasClass('toplevel_page_powered-cache')) {
15 return;
16 }
17
18 /**
19 * Modal: diagnosticModal Modal
20 *
21 * Run demo for performance test and close modal at the end.
22 */
23 function diagnosticModal() {
24 const activate = $('#pcmodal--powered-cache-diagnostic-test');
25
26 activate.on('click', function () {
27 const button = $(this);
28 const suiBox = button.closest('.sui-box');
29 const boxTitle = suiBox.find('.sui-box-title');
30 const boxSkip = suiBox.find('.sui-box-header button');
31 const diagnosticItems = suiBox.find('#powered-cache-diagnostic-items');
32 const nonce = $('#powered_cache_run_diagnostic').val();
33 const oldTitle = __('Diagnostic', 'powered-cache');
34
35 jQuery
36 .ajax({
37 url: ajaxurl,
38 method: 'post',
39 beforeSend() {
40 // Assign new title.
41 boxTitle.text(__('Running Diagnostic Tests…', 'powered-cache'));
42 // Disable "skip" button.
43 boxSkip.attr('disabled', true);
44 // clear previous message exists
45 diagnosticItems.empty();
46 },
47 data: {
48 nonce,
49 action: 'powered_cache_run_diagnostic',
50 },
51 success(response) {
52 if (response.success && response.data.length) {
53 response.data.forEach((item) => {
54 let icon = null;
55 if (item.status) {
56 icon =
57 '<span class="sui-icon-check" aria-hidden="true"></span>';
58 } else {
59 icon = (
60 <span className="sui-icon-close" aria-hidden="true" />
61 );
62 }
63
64 diagnosticItems.append(`<li>${icon} ${item.description}</li>`);
65 });
66 }
67 },
68 })
69 .done(function () {
70 // Assign old title.
71 boxTitle.text(oldTitle);
72 // Enable "skip" button.
73 boxSkip.removeAttr('disabled');
74 });
75 });
76 }
77
78 function init() {
79 diagnosticModal();
80 }
81
82 init();
83 };
84
85 $('body').ready(function () {
86 PoweredCache.pageModals('modals');
87 });
88 })(jQuery);
89