PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.15.1
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.15.1
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / view / javascript / np_safemode.js
nitropack / view / javascript Last commit date
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 });