admin_bar_menu.js
2 years ago
flowbite.min.js
2 years ago
gravity_forms.js
3 years ago
math_captcha.js
3 years ago
metabox.js
2 years ago
nitropackUI.js
2 years ago
np_notices.js
2 years ago
np_safemode.js
2 years ago
np_settings.js
2 years ago
popper.min.js
4 years ago
widgets_ajax.js
3 years ago
np_safemode.js
148 lines
| 1 | jQuery(document).ready(function ($) { |
| 2 | class nitropackDeactivate { |
| 3 | constructor() { |
| 4 | //vars |
| 5 | this.deactivateLink = 'tr[data-slug="nitropack"] #deactivate-nitropack'; |
| 6 | this.modal = $('#deactivate-modal'); |
| 7 | this.modal_state = 'close'; |
| 8 | //func |
| 9 | this.closeModalClick(); |
| 10 | this.deactivateClick(); |
| 11 | this.deactivation(); |
| 12 | this.enableTestMode(); |
| 13 | } |
| 14 | deactivateClick() { |
| 15 | const nitroSelf = this; |
| 16 | $(this.deactivateLink).on('click', function (e) { |
| 17 | e.preventDefault(); |
| 18 | nitroSelf.modalState('open'); |
| 19 | }); |
| 20 | } |
| 21 | deactivation() { |
| 22 | const nitroSelf = this, |
| 23 | deactivateLinkUrl = $(this.deactivateLink).attr('href'); |
| 24 | $('#np-safemode-nogo').on('click', function (e) { |
| 25 | nitroSelf.modalState('loading'); |
| 26 | e.preventDefault(); |
| 27 | e.stopPropagation(); |
| 28 | $(nitroSelf.deactivateLink).unbind('click'); //enable click |
| 29 | nitroSelf.modalState('close'); |
| 30 | if (deactivateLinkUrl !== '') { location.href = deactivateLinkUrl; } |
| 31 | }); |
| 32 | } |
| 33 | enableTestMode() { |
| 34 | const nitroSelf = this; |
| 35 | $('#np-safemode-go').on('click', function (e) { |
| 36 | e.preventDefault(); |
| 37 | e.stopPropagation(); |
| 38 | $(nitroSelf.deactivateLink).unbind('click'); |
| 39 | |
| 40 | $.ajax({ |
| 41 | url: ajaxurl, |
| 42 | type: 'POST', |
| 43 | data: { action: 'nitropack_enable_safemode', nonce: frontendajax.nitroNonce }, |
| 44 | beforeSend: function () { |
| 45 | nitroSelf.modalState('loading'); |
| 46 | }, |
| 47 | success: function (response) { |
| 48 | let responseResult = JSON.parse(response); |
| 49 | if (responseResult.type === 'success') { |
| 50 | nitroSelf.modalState(responseResult.type); |
| 51 | } else { |
| 52 | nitroSelf.modalState('error'); |
| 53 | } |
| 54 | }, |
| 55 | error: function () { |
| 56 | nitroSelf.modalState('error'); |
| 57 | }, |
| 58 | complete: function () { |
| 59 | setTimeout(function () { |
| 60 | nitroSelf.modalState('close'); |
| 61 | }, 1500); |
| 62 | } |
| 63 | }); |
| 64 | }); |
| 65 | } |
| 66 | modalState(state) { |
| 67 | const modal_wrapper = this.modal, |
| 68 | modal_text = modal_wrapper.find('.popup-body p'), |
| 69 | modal_title = modal_wrapper.find('.popup-header h3'), |
| 70 | modal_icon = modal_wrapper.find('.icon'), |
| 71 | modal_footer = modal_wrapper.find('.popup-footer'); |
| 72 | |
| 73 | let icon_url; |
| 74 | |
| 75 | switch (state) { |
| 76 | case 'open': |
| 77 | this.openModal(); |
| 78 | |
| 79 | icon_url = this.replaceIconNameInUrl(modal_icon.attr('src'), 'question-circle'); |
| 80 | modal_icon.attr('src', icon_url).removeClass('rotate-180'); |
| 81 | modal_title.text('Did you know?'); |
| 82 | modal_text.text('It is not necessary to deactivate NitroPack for troubleshooting. You can use our Test Mode insted. Do you still want to deactivate?'); |
| 83 | modal_footer.removeClass('hidden'); |
| 84 | break; |
| 85 | case 'close': |
| 86 | this.hideModal(); |
| 87 | break; |
| 88 | case 'loading': |
| 89 | icon_url = this.replaceIconNameInUrl(modal_icon.attr('src'), 'loading'); |
| 90 | modal_icon.attr('src', icon_url).removeClass('rotate-180'); |
| 91 | break; |
| 92 | case 'error': |
| 93 | icon_url = this.replaceIconNameInUrl(modal_icon.attr('src'), 'x-circle'); |
| 94 | modal_icon.attr('src', icon_url).removeClass('rotate-180'); |
| 95 | modal_title.text('Something went wrong!'); |
| 96 | modal_text.text(''); |
| 97 | modal_footer.addClass('hidden'); |
| 98 | break; |
| 99 | case 'success': |
| 100 | icon_url = this.replaceIconNameInUrl(modal_icon.attr('src'), 'check-circle-green'); |
| 101 | modal_icon.attr('src', icon_url).removeClass('rotate-180') |
| 102 | modal_title.text('Test Mode enabled.'); |
| 103 | modal_text.text(''); |
| 104 | modal_footer.addClass('hidden'); |
| 105 | break; |
| 106 | } |
| 107 | this.modal_state = state; |
| 108 | } |
| 109 | closeModalClick() { |
| 110 | const nitroSelf = this; |
| 111 | //esc key |
| 112 | $(document).keydown(function (event) { |
| 113 | if (event.keyCode == 27) nitroSelf.modalState('close'); |
| 114 | }); |
| 115 | //close button |
| 116 | this.modal.find('.close-modal').click(function () { |
| 117 | nitroSelf.modalState('close'); |
| 118 | }); |
| 119 | $(document).on('click', 'div[modal-backdrop]',function (e) { |
| 120 | nitroSelf.modalState('close'); |
| 121 | }); |
| 122 | } |
| 123 | //cosmetics |
| 124 | openModal() { |
| 125 | $('<div modal-backdrop></div>').appendTo('body'); |
| 126 | this.modal.removeClass('hidden'); |
| 127 | } |
| 128 | hideModal() { |
| 129 | this.modal.addClass('hidden'); |
| 130 | $('div[modal-backdrop]').remove(); |
| 131 | } |
| 132 | //helpers |
| 133 | replaceIconNameInUrl(url, newIconName) { |
| 134 | // Find the index of the last "/" |
| 135 | const lastSlashIndex = url.lastIndexOf('/'); |
| 136 | // Find the index of the ".svg" extension |
| 137 | const svgIndex = url.indexOf('.svg', lastSlashIndex); |
| 138 | // Extract the icon name between the last "/" and ".svg" |
| 139 | const currentIconName = url.substring(lastSlashIndex + 1, svgIndex); |
| 140 | // Construct the new URL with the replaced icon name |
| 141 | const newUrl = url.replace(currentIconName + '.svg', newIconName + '.svg'); |
| 142 | |
| 143 | return newUrl; |
| 144 | } |
| 145 | } |
| 146 | const NitroPackDeactivate = new nitropackDeactivate(); |
| 147 | window.NitroPackDeactivate = NitroPackDeactivate; |
| 148 | }); |