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
backup-adstxt.js
53 lines
| 1 | import jQuery from 'jquery'; |
| 2 | |
| 3 | function createNotice(message, type, after, fadeAway = false) { |
| 4 | const notice = jQuery( |
| 5 | `<div class="notice notice-${type} is-dismissible" />` |
| 6 | ); |
| 7 | notice.html( |
| 8 | '<div class="py-3">' + message + '</div>' |
| 9 | ); |
| 10 | after.after(notice); |
| 11 | |
| 12 | if (fadeAway) { |
| 13 | setTimeout(() => { |
| 14 | notice.fadeOut(500, () => { |
| 15 | notice.remove(); |
| 16 | }); |
| 17 | }, 3000); |
| 18 | } |
| 19 | jQuery(document).trigger( 'wp-notice-added'); |
| 20 | } |
| 21 | |
| 22 | export default function () { |
| 23 | jQuery(document).on('click', '.js-btn-backup-adstxt', function () { |
| 24 | const button = jQuery(this); |
| 25 | const wrap = button.closest('.notice'); |
| 26 | button.prop('disabled', true); |
| 27 | button.html(button.data('loading')); |
| 28 | |
| 29 | jQuery |
| 30 | .ajax({ |
| 31 | url: advancedAds.endpoints.ajaxUrl, |
| 32 | method: 'POST', |
| 33 | data: { |
| 34 | action: 'pubguru_backup_ads_txt', |
| 35 | security: button.data('security'), |
| 36 | }, |
| 37 | }) |
| 38 | .always(() => { |
| 39 | button.prop('disabled', false); |
| 40 | button.html(button.data('text')); |
| 41 | }) |
| 42 | .done((result) => { |
| 43 | if (result.success) { |
| 44 | createNotice(result.data, 'success', wrap, true); |
| 45 | wrap.remove(); |
| 46 | } else { |
| 47 | createNotice(result.data, 'error', wrap); |
| 48 | wrap.remove(); |
| 49 | } |
| 50 | }); |
| 51 | }); |
| 52 | } |
| 53 |