components
2 years ago
addons-admin-page.js
4 years ago
donation-options.ts
3 years ago
payment-gateway.ts
3 years ago
sale-banner.js
4 years ago
utils.js
4 years ago
sale-banner.js
33 lines
| 1 | const bannersContainer = document.querySelector('.give-sale-banners-container'); |
| 2 | const dismissActions = document.querySelectorAll('.give-sale-banner-dismiss'); |
| 3 | const pageTitle = document.querySelector('.page-title-action, .wp-heading-inline, #give-in-plugin-upsells h1'); |
| 4 | |
| 5 | const hideBanner = ({target: dismissAction}) => { |
| 6 | const formData = new FormData(); |
| 7 | formData.append('id', dismissAction.dataset.id); |
| 8 | |
| 9 | document.getElementById(dismissAction.getAttribute('aria-controls')).remove(); |
| 10 | |
| 11 | fetch(`${window.GiveSaleBanners.apiRoot}/hide`, { |
| 12 | method: 'POST', |
| 13 | headers: { |
| 14 | 'X-WP-Nonce': window.GiveSaleBanners.apiNonce, |
| 15 | }, |
| 16 | body: formData, |
| 17 | }); |
| 18 | |
| 19 | if (bannersContainer.querySelectorAll('.give-sale-banner').length === 0) { |
| 20 | bannersContainer.remove(); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | if (pageTitle && bannersContainer) { |
| 25 | pageTitle.parentNode.insertBefore(bannersContainer, pageTitle.nextSibling); |
| 26 | |
| 27 | bannersContainer.style.display = null; |
| 28 | } |
| 29 | |
| 30 | dismissActions.forEach((action) => { |
| 31 | action.addEventListener('click', hideBanner); |
| 32 | }); |
| 33 |