script.js
75 lines
| 1 | // Always close the code, cause you can make conflicts (same for css use prefixes) |
| 2 | (function ($) { |
| 3 | |
| 4 | |
| 5 | let nonce = new_bb_banner.dismiss_nonce; |
| 6 | let is_backup_pro_exists = new_bb_banner.is_backup_pro_exists; |
| 7 | let current_plugin = new_bb_banner.current_plugin; |
| 8 | let is_bmi_exists = new_bb_banner.is_bmi_exists; |
| 9 | |
| 10 | console.log('is_backup_pro_exists', is_backup_pro_exists); |
| 11 | if (is_backup_pro_exists) { |
| 12 | $('#bmi-banner__card-premium-external-storage').show(); |
| 13 | $('#bmi-banner__card-free-external-storage').hide(); |
| 14 | |
| 15 | $('#bmi-banner__card-premium-storage').show(); |
| 16 | $('#bmi-banner__card-free-storage').hide(); |
| 17 | |
| 18 | $('#bmi-banner__card-4gb-upgraded').hide(); |
| 19 | |
| 20 | } else { |
| 21 | $('#bmi-banner__card-premium-external-storage').hide(); |
| 22 | $('#bmi-banner__card-free-external-storage').show(); |
| 23 | |
| 24 | $('#bmi-banner__card-premium-storage').hide(); |
| 25 | $('#bmi-banner__card-free-storage').show(); |
| 26 | |
| 27 | $('#bmi-banner__card-4gb-upgraded').show(); |
| 28 | } |
| 29 | |
| 30 | function banner_hide() { |
| 31 | $('#new-bb-banner').hide(300); |
| 32 | } |
| 33 | |
| 34 | $('.bmi-banner__cta-button.redirect-to-bmi').on('click', function () { |
| 35 | |
| 36 | let currentUrl = window.location.href; |
| 37 | let shouldRedirectToBMI = false; |
| 38 | |
| 39 | if (!currentUrl.includes('page=backup-migration')) { |
| 40 | shouldRedirectToBMI = true; |
| 41 | } |
| 42 | |
| 43 | $.post(ajaxurl, { |
| 44 | action: 'dismiss_new_bb_banner', |
| 45 | nonce: nonce, |
| 46 | token: 'new_bb_banner', |
| 47 | shouldRedirectToBMI: shouldRedirectToBMI |
| 48 | }).done(function (res) { |
| 49 | if (shouldRedirectToBMI && res.data.redirect) { |
| 50 | window.location.href = res.data.redirect; |
| 51 | } |
| 52 | }).fail(function (err) { |
| 53 | console.error(err); |
| 54 | }); |
| 55 | |
| 56 | banner_hide(); |
| 57 | |
| 58 | }); |
| 59 | |
| 60 | $('.bmi-banner__dismiss-link, .bmi-banner__close').on('click', function (e) { |
| 61 | e.preventDefault(); |
| 62 | $.post(ajaxurl, { |
| 63 | action: 'dismiss_new_bb_banner', |
| 64 | nonce: nonce, |
| 65 | token: 'new_bb_banner' |
| 66 | }).done(function (res) { |
| 67 | }).fail(function (err) { |
| 68 | console.error(err); |
| 69 | }); |
| 70 | |
| 71 | banner_hide(); |
| 72 | }); |
| 73 | |
| 74 | })(jQuery); |
| 75 |