PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.19.3
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.19.3
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 / nitropackUI.js
nitropack / view / javascript Last commit date
admin_bar_menu.js 4 months ago elementor_cache_integration.js 5 months ago flowbite.min.js 1 year ago gravity_forms.js 1 year ago math_captcha.js 1 year ago nitropackUI.js 3 months ago np_notices.js 3 months ago np_safemode.js 1 year ago np_settings.js 3 months ago popper.min.js 1 year ago post_clear_cache.js 4 months ago preview_site.js 3 months ago system_report.js 4 months ago widgets_ajax.js 1 year ago
nitropackUI.js
309 lines
1 /**
2 * Simple Modal — drop-in replacement for Flowbite Modal.
3 * Supports: new Modal(el, options), .show(), .hide(), .toggle(),
4 * data-modal-hide, data-modal-show, data-modal-toggle attributes,
5 * ESC to close, .close-modal buttons, backdrop click to close.
6 */
7 (function () {
8 'use strict';
9
10 var instances = {};
11
12 function Modal(el, options) {
13 if (typeof el === 'string') el = document.getElementById(el);
14 if (!el) return;
15
16 this._el = el;
17 this._options = Object.assign({ backdrop: 'dynamic' }, options);
18 this._backdrop = null;
19 this._isVisible = false;
20 this._onKeydown = this._handleKeydown.bind(this);
21
22 if (el.id) instances[el.id] = this;
23 }
24
25 Modal.prototype.show = function () {
26 if (this._isVisible) return;
27 this._isVisible = true;
28 this._createBackdrop();
29 this._el.classList.remove('hidden');
30 this._el.setAttribute('aria-hidden', 'false');
31 document.body.style.overflow = 'hidden';
32 document.addEventListener('keydown', this._onKeydown);
33 };
34
35 Modal.prototype.hide = function () {
36 if (!this._isVisible) return;
37 this._isVisible = false;
38 this._el.classList.add('hidden');
39 this._el.setAttribute('aria-hidden', 'true');
40 this._removeBackdrop();
41 document.body.style.overflow = '';
42 document.removeEventListener('keydown', this._onKeydown);
43 };
44
45 Modal.prototype.toggle = function () {
46 this._isVisible ? this.hide() : this.show();
47 };
48
49 Modal.prototype.isVisible = function () {
50 return this._isVisible;
51 };
52
53 Modal.prototype._handleKeydown = function (e) {
54 if (e.key === 'Escape' && this._options.backdrop !== 'static') {
55 this.hide();
56 }
57 };
58
59 Modal.prototype._createBackdrop = function () {
60 if (this._options.backdrop === false) return;
61 this._backdrop = document.createElement('div');
62 this._backdrop.setAttribute('modal-backdrop', '');
63 document.body.appendChild(this._backdrop);
64
65 if (this._options.backdrop !== 'static') {
66 var self = this;
67 this._el.addEventListener('click', this._onWrapperClick = function (e) {
68 if (e.target === self._el) self.hide();
69 });
70 }
71 };
72
73 Modal.prototype._removeBackdrop = function () {
74 if (this._backdrop && this._backdrop.parentNode) {
75 this._backdrop.parentNode.removeChild(this._backdrop);
76 this._backdrop = null;
77 }
78 if (this._onWrapperClick) {
79 this._el.removeEventListener('click', this._onWrapperClick);
80 this._onWrapperClick = null;
81 }
82 };
83
84 Modal.getInstance = function (id) {
85 return instances[id] || null;
86 };
87
88 // Auto-init modals from DOM & bind declarative attributes
89 function initModals() {
90 // Create instances for elements with data-modal-backdrop
91 document.querySelectorAll('.modal-wrapper').forEach(function (el) {
92 if (!el.id || instances[el.id]) return;
93 console.log(el.id);
94 var backdrop = el.getAttribute('data-modal-backdrop') || 'dynamic';
95 new Modal(el, { backdrop: backdrop });
96 });
97
98 // data-modal-show
99 document.querySelectorAll('[data-modal-show]').forEach(function (trigger) {
100 var id = trigger.getAttribute('data-modal-show');
101 trigger.addEventListener('click', function () {
102 var inst = instances[id];
103 if (inst) inst.show();
104 });
105 });
106
107 // data-modal-hide
108 document.querySelectorAll('[data-modal-hide]').forEach(function (trigger) {
109 var id = trigger.getAttribute('data-modal-hide');
110 trigger.addEventListener('click', function () {
111 var inst = instances[id];
112 if (inst) inst.hide();
113 });
114 });
115
116 // data-modal-toggle
117 document.querySelectorAll('[data-modal-toggle]').forEach(function (trigger) {
118 var id = trigger.getAttribute('data-modal-toggle');
119
120 trigger.addEventListener('click', function () {
121 var inst = instances[id];
122 console.log(instances);
123 if (inst) inst.toggle();
124 });
125 });
126
127 // .close-modal buttons — close the closest .modal-wrapper
128 document.querySelectorAll('.close-modal').forEach(function (btn) {
129 btn.addEventListener('click', function () {
130 var wrapper = btn.closest('.modal-wrapper');
131 if (wrapper && wrapper.id && instances[wrapper.id]) {
132 instances[wrapper.id].hide();
133 }
134 });
135 });
136 }
137
138 window.Modal = Modal;
139 window.initModals = initModals;
140
141 if (document.readyState === 'loading') {
142 document.addEventListener('DOMContentLoaded', initModals);
143 } else {
144 initModals();
145 }
146 })();
147
148 jQuery(document).ready(function ($) {
149 class nitropackUI {
150 constructor() {
151 this.closeToast();
152 this.highlight_columns();
153 this.cosmetics();
154
155 //toasts
156 this.elapsedToastTime = 0;
157 }
158 triggerToast(status, msg) {
159 if (!status) return;
160 const nitroSelf = this,
161 toast_wrapper = $('.toast-wrapper').eq(0),
162 toast_text = toast_wrapper.find('.msg-box .text'),
163 toast_icon = toast_wrapper.find('.icon img');
164 var css_status = 'toast-' + status;
165
166 if (toast_wrapper.hasClass('shown')) {
167 //clone and hide prev toast
168 const clone = toast_wrapper.clone();
169 this.duplicateToast(clone, status, msg);
170 nitroSelf.hideToast(toast_wrapper);
171 } else {
172 //adjust text and show
173 toast_text.html(msg);
174 this.replaceIcon(status, toast_icon);
175 toast_wrapper.addClass('shown ' + css_status);
176 }
177 this.pauseAndHide(toast_wrapper);
178 }
179 pauseAndHide(toast_wrapper) {
180 const nitroSelf = this,
181 remainingTime = 1500;
182 var showedTime = Date.now(),
183 timeoutId,
184 currentRemaining = 1500;
185
186 timeoutId = setTimeout(function () {
187 nitroSelf.hideToast(toast_wrapper);
188 }, remainingTime);
189 //Pause timeout on mouse hover
190 toast_wrapper.on('mouseenter', function () {
191 nitroSelf.elapsedToastTime = Date.now() - showedTime;
192 clearTimeout(timeoutId);
193 });
194 //Resume timeout on mouse leave
195 toast_wrapper.on('mouseleave', function () {
196 showedTime = Date.now() - nitroSelf.elapsedToastTime; //track on multiple hover the correct showed time and apply to elapsedToastTime
197
198 currentRemaining = Math.max(remainingTime - nitroSelf.elapsedToastTime, 0); // Calculate remaining time
199
200 timeoutId = setTimeout(function () {
201 nitroSelf.hideToast(toast_wrapper);
202 }, currentRemaining);
203 });
204 }
205 duplicateToast(clone, status, msg) {
206 const toast_wrapper = $('.toast-wrapper');
207 var visible_toasts = $('.toast-wrapper.shown').length,
208 css_status = 'toast-' + status,
209 bottom = 8 + (5 * (visible_toasts - 1)), //multiply by 5, first is 8
210 toast_icon = clone.find('.icon img');
211
212 clone.find('.msg-box .text').html(msg);
213 this.replaceIcon(status, toast_icon);
214 this.hideToast(clone);
215
216 clone.insertBefore(toast_wrapper.eq(0));
217
218 setTimeout(function () {
219 clone.addClass(css_status + ' shown');
220
221 }, 250);
222 this.pauseAndHide(clone);
223 }
224 toastIcon(status) {
225 const icon = {
226 'error': 'alert-triangle',
227 'success': 'check-circle-green',
228 'info': 'info-circle-blue'
229 };
230 return icon[status];
231 }
232 replaceIcon(status, toast_icon) {
233 var new_icon = this.toastIcon(status),
234 icon_url = this.replaceIconNameInUrl(toast_icon.attr('src'), new_icon);
235 toast_icon.attr('src', icon_url);
236 }
237 replaceIconNameInUrl(url, newIconName) {
238 // Find the index of the last "/"
239 const lastSlashIndex = url.lastIndexOf('/');
240 // Find the index of the ".svg" extension
241 const svgIndex = url.indexOf('.svg', lastSlashIndex);
242 // Extract the icon name between the last "/" and ".svg"
243 const currentIconName = url.substring(lastSlashIndex + 1, svgIndex);
244 // Construct the new URL with the replaced icon name
245 const newUrl = url.replace(currentIconName + '.svg', newIconName + '.svg');
246
247 return newUrl;
248 }
249 closeToast() {
250 const nitroSelf = this;
251 $(document).on('click', '.toast-close', function () {
252 const el = $(this).closest('.toast-wrapper');
253 nitroSelf.hideToast(el)
254 });
255 }
256 hideToast(el) {
257 el.removeClass('shown toast-success toast-error toast-info');
258 }
259 //end of toasts
260 tabs() {
261 $('.tabs .tab-link').click(function () {
262 let tab = $(this).data('tab'),
263 tab_content_wrapper = $(this).closest('.tabs-wrapper').find('.tab-content-wrapper');
264 tab_content_wrapper.find('.tab-content').addClass('hidden');
265 tab_content_wrapper.find('.tab-content[data-tab="' + tab + '-tab"].hidden').removeClass('hidden');
266 });
267 }
268 highlight_columns() {
269 $('.modes .mode').on("mouseenter", function () {
270 var columnIndex = $(this).index(); // Get the index of the cell within its parent container
271 $(this).addClass('current-highlight')
272 $('.modes .mode:nth-child(' + (columnIndex + 1) + ')').addClass("highlight-column");
273 // Add the background class to all cells in the same column
274 }).on("mouseleave", function () {
275 $('.modes .mode').removeClass("highlight-column current-highlight");
276 // Remove the background class from all cells
277 });
278 }
279 toggle_submenu() {
280 $('.toggle-dropdown').click(function () {
281 let parent_li = $(this).closest('.list-item'),
282 child_ul = parent_li.find('ul'),
283 toggle_btn = $(this);
284 child_ul.toggleClass('opened');
285 toggle_btn.toggleClass('rotate-180');
286 });
287 }
288 posttype_taxonomy_counter() {
289 $('#modal-posttypes .taxonomies label input').click(function () {
290 var parent_li = $(this).closest('.sub-menu').parent('.list-item'),
291 counter_div = parent_li.find('.count'),
292 counter = counter_div.text() * 1;
293 if ($(this).is(':checked')) {
294 counter++
295 } else {
296 counter--
297 }
298 counter_div.text(counter);
299 });
300 }
301 cosmetics() {
302 $('.tooltip-container').removeClass('hidden');
303 }
304
305
306 }
307 const NitropackUI = new nitropackUI();
308 window.NitropackUI = NitropackUI;
309 });