# powered-cache/2.0.2/assets/js/admin/modules/modal.js

Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed &amp; Web Vitals Score, version 2.0.2. 89 lines.

- Page: https://pluginprobe.com/plugins/powered-cache/2.0.2/code/assets/js/admin/modules/modal.js
- Raw: https://pluginprobe.com/plugins/powered-cache/2.0.2/raw/assets/js/admin/modules/modal.js
- Modified: 2021-08-26T10:31:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/powered-cache/2.0.2/code/assets/js/admin/modules/modal.js#L10-L20`.

```javascript
/* global jQuery, PoweredCache, ajaxurl  */
const { __ } = wp.i18n;

(function ($) {
	// Use strict mode

	// Define global PoweredCache object if it does not exist
	if (typeof window.PoweredCache !== 'object') {
		window.PoweredCache = {};
	}

	PoweredCache.pageModals = function () {
		const body = $('body');
		if (!body.hasClass('toplevel_page_powered-cache')) {
			return;
		}

		/**
		 * Modal: diagnosticModal Modal
		 *
		 * Run demo for performance test and close modal at the end.
		 */
		function diagnosticModal() {
			const activate = $('#pcmodal--powered-cache-diagnostic-test');

			activate.on('click', function () {
				const button = $(this);
				const suiBox = button.closest('.sui-box');
				const boxTitle = suiBox.find('.sui-box-title');
				const boxSkip = suiBox.find('.sui-box-header button');
				const diagnosticItems = suiBox.find('#powered-cache-diagnostic-items');
				const nonce = $('#powered_cache_run_diagnostic').val();
				const oldTitle = __('Diagnostic', 'powered-cache');

				jQuery
					.ajax({
						url: ajaxurl,
						method: 'post',
						beforeSend() {
							// Assign new title.
							boxTitle.text(__('Running Diagnostic Tests…', 'powered-cache'));
							// Disable "skip" button.
							boxSkip.attr('disabled', true);
							// clear previous message exists
							diagnosticItems.empty();
						},
						data: {
							nonce,
							action: 'powered_cache_run_diagnostic',
						},
						success(response) {
							if (response.success && response.data.length) {
								response.data.forEach((item) => {
									let icon = null;
									if (item.status) {
										icon =
											'<span class="sui-icon-check" aria-hidden="true"></span>';
									} else {
										icon = (
											<span className="sui-icon-close" aria-hidden="true" />
										);
									}

									diagnosticItems.append(`<li>${icon} ${item.description}</li>`);
								});
							}
						},
					})
					.done(function () {
						// Assign old title.
						boxTitle.text(oldTitle);
						// Enable "skip" button.
						boxSkip.removeAttr('disabled');
					});
			});
		}

		function init() {
			diagnosticModal();
		}

		init();
	};

	$('body').ready(function () {
		PoweredCache.pageModals('modals');
	});
})(jQuery);

```
