addon-box.js
3 months ago
addons.css
1 month ago
backup-adstxt.js
3 months ago
dashboard.css
3 months ago
index.js
3 months ago
oneclick.css
3 months ago
spinner.css
3 months ago
subscribe.js
3 months ago
welcome.js
3 months ago
addon-box.js
108 lines
| 1 | /** |
| 2 | * Background plugin activation |
| 3 | * |
| 4 | * @param {string} plugin path to the plugin's main file relative to WP's plugins folder. |
| 5 | * @param {string} name the plugin name. |
| 6 | * @param {string} nonce ajax nonce. |
| 7 | * @param {Element} button the button that triggered the activation |
| 8 | */ |
| 9 | const activateAddOn = (plugin, name, nonce, button) => { |
| 10 | button.classList.add('disabled'); |
| 11 | const slug = plugin.substring(plugin.indexOf('/') + 1, plugin.indexOf('.')); |
| 12 | wp.ajax |
| 13 | .post('advads_activate_addon', { |
| 14 | _ajax_nonce: nonce, |
| 15 | plugin, |
| 16 | slug, |
| 17 | name, |
| 18 | }) |
| 19 | .done(function () { |
| 20 | button.className = 'button active disabled'; |
| 21 | button.innerText = window.advadstxt.active; |
| 22 | const icon = document.createElement('i'); |
| 23 | icon.className = 'dashicons'; |
| 24 | icon.style.cssText = 'content:"\\f147"'; |
| 25 | button.insertBefore(icon, button.firstChild); |
| 26 | }) |
| 27 | .fail(function (response) { |
| 28 | if ('undefined' !== typeof response.errorMessage) { |
| 29 | // Error message from `wp_ajax_activate_plugin()`. |
| 30 | button |
| 31 | .closest('.cta') |
| 32 | .parentNode.querySelector('.description').innerText = |
| 33 | response.errorMessage; |
| 34 | } |
| 35 | }); |
| 36 | }; |
| 37 | |
| 38 | export default function () { |
| 39 | const addonBox = document.getElementById('advads_overview_addons'); |
| 40 | |
| 41 | if (!addonBox) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | addonBox.addEventListener('click', (ev) => { |
| 46 | const target = ev.target; |
| 47 | |
| 48 | if ( |
| 49 | 'a' === target.tagName.toLowerCase() && |
| 50 | target.classList.contains('disabled') |
| 51 | ) { |
| 52 | ev.preventDefault(); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | // Newsletter subscription. |
| 57 | if ( |
| 58 | target.classList.contains('button') && |
| 59 | target.classList.contains('subscribe') |
| 60 | ) { |
| 61 | ev.preventDefault(); |
| 62 | target.disabled = true; |
| 63 | target.classList.add('disabled'); |
| 64 | |
| 65 | wp.ajax |
| 66 | .post('advads_newsletter', { |
| 67 | nonce: target.dataset.nonce, |
| 68 | }) |
| 69 | .done(function (response) { |
| 70 | if (response) { |
| 71 | target |
| 72 | .closest('.item-details') |
| 73 | .querySelector('.description').innerHTML = |
| 74 | `<p style="font-weight: 600;">${response}</p>`; |
| 75 | } |
| 76 | }) |
| 77 | .fail(function (response) { |
| 78 | try { |
| 79 | target |
| 80 | .closest('.item-details') |
| 81 | .querySelector('.description').innerHTML = |
| 82 | `<p style="font-weight: 600;">${response.responseJSON.data.message}</p>`; |
| 83 | } catch (e) {} |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | // Background plugin activation |
| 88 | if ( |
| 89 | target.classList.contains('button') && |
| 90 | target.classList.contains('installed') |
| 91 | ) { |
| 92 | const marker = '#activate-aaplugin_'; |
| 93 | const href = target.href ? target.href : ''; |
| 94 | |
| 95 | if (-1 !== href.indexOf(marker)) { |
| 96 | ev.preventDefault(); |
| 97 | const data = href.split('_'); |
| 98 | activateAddOn( |
| 99 | data[2], |
| 100 | decodeURIComponent(data[3]), |
| 101 | data[1], |
| 102 | target |
| 103 | ); |
| 104 | } |
| 105 | } |
| 106 | }); |
| 107 | } |
| 108 |