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
2 years ago
utils.js
4 years ago
sale-banner.js
44 lines
| 1 | const bannersContainer = document.querySelector('.givewp-sale-banners-container'); |
| 2 | const dismissActions = document.querySelectorAll('.givewp-sale-banner__dismiss'); |
| 3 | const pageTitle = document.querySelector('.page-title-action, .wp-heading-inline, #give-in-plugin-upsells h1'); |
| 4 | const listTable = document.querySelector('#give-admin-donations-root, #give-admin-donation-forms-root, #give-admin-donors-root'); |
| 5 | const settings = document.querySelector('.give-settings-header'); |
| 6 | |
| 7 | /** |
| 8 | * @since 3.13.0 move placement of banner on Reports page. |
| 9 | * @since 3.1.0 show banner on ListTable pages. |
| 10 | */ |
| 11 | const hideBanner = ({target: dismissAction}) => { |
| 12 | const formData = new FormData(); |
| 13 | formData.append('id', dismissAction.dataset.id); |
| 14 | |
| 15 | document.getElementById(dismissAction.getAttribute('aria-controls')).remove(); |
| 16 | |
| 17 | fetch(`${window.GiveSaleBanners.apiRoot}/hide`, { |
| 18 | method: 'POST', |
| 19 | headers: { |
| 20 | 'X-WP-Nonce': window.GiveSaleBanners.apiNonce, |
| 21 | }, |
| 22 | body: formData, |
| 23 | }); |
| 24 | |
| 25 | if (bannersContainer.querySelectorAll('.givewp-sale-banner').length === 0) { |
| 26 | bannersContainer.remove(); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | if ((pageTitle || listTable) && bannersContainer) { |
| 32 | bannersContainer.style.display = null; |
| 33 | |
| 34 | if (settings) { |
| 35 | settings.insertAdjacentElement('afterend', bannersContainer); |
| 36 | } else if (listTable) { |
| 37 | listTable.querySelector('header').insertAdjacentElement('afterend', bannersContainer); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | dismissActions.forEach((action) => { |
| 42 | action.addEventListener('click', hideBanner); |
| 43 | }); |
| 44 |