icons
1 week ago
custom-post-types.js
8 months ago
redundant-plugins-notice.js
4 days ago
review-notice.js
6 days ago
settings-src.css
4 days ago
settings.css
4 days ago
redundant-plugins-notice.js
65 lines
| 1 | /** |
| 2 | * FrontBlocks Redundant Plugins Notice |
| 3 | * |
| 4 | * Handles dismissal of the redundant-plugin admin notices. Unlike the review |
| 5 | * notice, dismissal here is scoped to a state hash (which plugins/versions |
| 6 | * were detected): the notice reappears if that state changes later. |
| 7 | */ |
| 8 | |
| 9 | (function () { |
| 10 | 'use strict'; |
| 11 | |
| 12 | document.addEventListener('DOMContentLoaded', function () { |
| 13 | var notices = document.querySelectorAll('.frbl-redundant-plugin-notice'); |
| 14 | |
| 15 | if (!notices.length) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | function sendDismiss(entryId, stateHash) { |
| 20 | var data = new FormData(); |
| 21 | data.append('action', 'frbl_dismiss_redundant_plugin_notice'); |
| 22 | data.append('nonce', frblRedundantPluginsNotice.nonce); |
| 23 | data.append('entry_id', entryId); |
| 24 | data.append('state_hash', stateHash); |
| 25 | |
| 26 | return fetch(frblRedundantPluginsNotice.ajaxurl, { |
| 27 | method: 'POST', |
| 28 | body: data |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | notices.forEach(function (notice) { |
| 33 | var entryId = notice.getAttribute('data-entry-id'); |
| 34 | var stateHash = notice.getAttribute('data-state-hash'); |
| 35 | var dismissLink = notice.querySelector('.frbl-dismiss-redundant-plugin'); |
| 36 | |
| 37 | function dismiss(e) { |
| 38 | if (e) { |
| 39 | e.preventDefault(); |
| 40 | } |
| 41 | |
| 42 | // Only hide once the dismissal is actually saved, so the notice |
| 43 | // doesn't silently vanish while a dropped request leaves the |
| 44 | // server-side state undismissed. |
| 45 | sendDismiss(entryId, stateHash).then(function (response) { |
| 46 | if (response.ok) { |
| 47 | notice.style.display = 'none'; |
| 48 | } |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | if (dismissLink) { |
| 53 | dismissLink.addEventListener('click', dismiss); |
| 54 | } |
| 55 | |
| 56 | // WordPress built-in dismiss button (.notice-dismiss), if present. |
| 57 | notice.addEventListener('click', function (e) { |
| 58 | if (e.target && e.target.classList.contains('notice-dismiss')) { |
| 59 | dismiss(); |
| 60 | } |
| 61 | }); |
| 62 | }); |
| 63 | }); |
| 64 | }()); |
| 65 |