optin.php
62 lines
| 1 | <script type="text/javascript"> |
| 2 | |
| 3 | (function ($) { |
| 4 | var isOptingIn = false |
| 5 | |
| 6 | $('#analyst-opt-in-modal').appendTo($('body')) |
| 7 | |
| 8 | var makeOptIn = function (pluginId) { |
| 9 | if (isOptingIn) return |
| 10 | |
| 11 | isOptingIn = true |
| 12 | |
| 13 | $.ajax({ |
| 14 | url: ajaxurl, |
| 15 | method: 'POST', |
| 16 | data: { |
| 17 | action: 'analyst_opt_in_' + pluginId, |
| 18 | nonce: analyst_opt_localize.nonce |
| 19 | }, |
| 20 | success: function () { |
| 21 | $('#analyst-opt-in-modal').hide() |
| 22 | |
| 23 | isOptingIn = false |
| 24 | |
| 25 | var optOutAction = $('<a />').attr({ |
| 26 | class: 'analyst-action-opt analyst-opt-out', |
| 27 | 'analyst-plugin-id': pluginId, |
| 28 | 'analyst-plugin-signed': '1' |
| 29 | }) |
| 30 | .text('Opt Out') |
| 31 | $('.analyst-opt-in[analyst-plugin-id="'+ pluginId +'"').replaceWith(optOutAction) |
| 32 | |
| 33 | $('[analyst-plugin-id="' + pluginId + '"').attr('analyst-plugin-opted-in', 1) |
| 34 | } |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | $(document).on('click', '.analyst-opt-in:not([loading])', function() { |
| 39 | var pluginId = $(this).attr('analyst-plugin-id') |
| 40 | var isSigned = $(this).attr('analyst-plugin-signed') === '1' |
| 41 | |
| 42 | if (!isSigned) { |
| 43 | $('#analyst-install-modal') |
| 44 | .attr('analyst-plugin-id', pluginId) |
| 45 | .show() |
| 46 | |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | $('#analyst-install-modal').attr({'analyst-plugin-id': pluginId}) |
| 51 | |
| 52 | $(this).attr('loading', true).text('Opting In...') |
| 53 | |
| 54 | makeOptIn(pluginId); |
| 55 | }) |
| 56 | |
| 57 | $('.opt-in-modal-close').click(function () { |
| 58 | $('#analyst-opt-in-modal').hide() |
| 59 | }) |
| 60 | })(jQuery) |
| 61 | </script> |
| 62 |