polyfill.js
3 years ago
scripts.js
2 months ago
scripts.js.map
3 years ago
scripts_admin copy.js
4 years ago
scripts_admin.js
1 year ago
scripts_admin_all_pages.js
8 months ago
scripts_es6.js
3 years ago
temp.js
4 years ago
scripts_admin_all_pages.js
50 lines
| 1 | // ------------------------------------ |
| 2 | // DISMISS NOTICES |
| 3 | // ------------------------------------ |
| 4 | |
| 5 | document.addEventListener('DOMContentLoaded', () => { |
| 6 | // Delegated click handler covers notices added later, too |
| 7 | document.addEventListener('click', (event) => { |
| 8 | const trigger = event.target.closest( |
| 9 | '.wpcf7cf-admin-notice .notice-dismiss, .wpcf7cf-admin-notice .notice-dismiss-alt' |
| 10 | ); |
| 11 | if (!trigger) return; |
| 12 | |
| 13 | event.preventDefault(); |
| 14 | |
| 15 | const noticeEl = trigger.closest('.wpcf7cf-admin-notice'); |
| 16 | if (!noticeEl) return; |
| 17 | |
| 18 | const noticeId = noticeEl.dataset.noticeId || ''; |
| 19 | const nonce = noticeEl.dataset.nonce || ''; |
| 20 | |
| 21 | // Update hidden input when noticeId is empty (parity with original) |
| 22 | if (noticeId === '') { |
| 23 | const input = document.querySelector('input[name="wpcf7cf_options[notice_dismissed]"]'); |
| 24 | if (input) input.value = 'true'; |
| 25 | } |
| 26 | |
| 27 | // Fire AJAX (needs admin `ajaxurl`; front-end must localize it) |
| 28 | if (typeof ajaxurl !== 'undefined') { |
| 29 | const params = new URLSearchParams(); |
| 30 | params.append('action', 'wpcf7cf_dismiss_notice'); |
| 31 | params.append('noticeId', noticeId); |
| 32 | params.append('nonce', nonce); |
| 33 | |
| 34 | fetch(ajaxurl, { |
| 35 | method: 'POST', |
| 36 | credentials: 'same-origin', |
| 37 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |
| 38 | body: params.toString(), |
| 39 | cache: 'no-cache' |
| 40 | }).then((response) => { |
| 41 | if (response.ok) { |
| 42 | // Remove notice from DOM on success |
| 43 | noticeEl.remove(); |
| 44 | } |
| 45 | }).catch(() => { |
| 46 | // Silently fail |
| 47 | }); |
| 48 | } |
| 49 | }); |
| 50 | }); |