PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 7.4.1
WP Popular Posts v7.4.1
7.4.1 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / assets / js / admin-notices.js
wordpress-popular-posts / assets / js Last commit date
blocks 1 week ago vendor 4 years ago admin-notices.js 1 year ago admin.js 1 week ago chart.js 1 week ago wpp.js 1 week ago wpp.min.js 1 week ago
admin-notices.js
78 lines
1 'use strict';
2
3 document.addEventListener('DOMContentLoaded', () => {
4 const btnNagDismiss = document.querySelector('.wpp-dismiss-performance-notice');
5 const btnNagRemind = document.querySelector('.wpp-remind-performance-notice');
6
7 if ( btnNagDismiss && btnNagRemind ) {
8 btnNagDismiss.addEventListener('click', (e) => {
9 e.preventDefault();
10 handleNagClick(e, '1');
11 });
12
13 btnNagRemind.addEventListener('click', (e) => {
14 e.preventDefault();
15 handleNagClick(e, '-1');
16 });
17 }
18
19 function handleNagClick(e, dismissValue) {
20 const me = e.target;
21
22 btnNagRemind.classList.add('disabled');
23 btnNagDismiss.classList.add('disabled');
24
25 me.parentNode.querySelector('.spinner').classList.add('is-active');
26
27 ajax(
28 'POST',
29 ajaxurl,
30 `action=wpp_handle_performance_notice&dismiss=${dismissValue}&token=${wpp_admin_notices_params.nonce_performance_nag}`,
31 (response) => handleNotice(response, me)
32 );
33 }
34
35 function handleNotice(response, btn) {
36 const json = JSON.parse(response);
37
38 if ( json.status === 'success' ) {
39 const notice = btn.parentNode.parentNode;
40 notice.parentNode.removeChild(notice);
41 } else {
42 alert('Something went wrong, please try again later');
43 }
44
45 btnNagRemind.classList.remove('disabled');
46 btnNagDismiss.classList.remove('disabled');
47 btn.parentNode.querySelector('.spinner').classList.remove('is-active');
48 }
49
50 function ajax(method, url, params, callback) {
51 const validMethods = ['GET', 'POST'];
52 const headers = {
53 'X-Requested-With': 'XMLHttpRequest'
54 };
55
56 if ( ! validMethods.includes(method) ) {
57 method = 'GET';
58 }
59
60 if ( method === 'POST' ) {
61 headers['Content-Type'] = 'application/x-www-form-urlencoded';
62 }
63
64 fetch(url + (method === 'GET' ? '?' + params : ''), {
65 method,
66 headers,
67 body: method === 'POST' ? params : null
68 })
69 .then(response => {
70 if ( ! response.ok ) {
71 throw new Error('Network response was not ok');
72 }
73 return response.text();
74 })
75 .then(data => callback(data))
76 .catch(error => console.error('Fetch error:', error));
77 }
78 });