PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.16.1
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.16.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 / nitropackUI.js
nitropack / view / javascript Last commit date
admin_bar_menu.js 1 year 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
nitropackUI.js
161 lines
1 jQuery(document).ready(function ($) {
2 class nitropackUI {
3 constructor() {
4 this.closeToast();
5 this.highlight_columns();
6 this.cosmetics();
7
8 //toasts
9 this.elapsedToastTime = 0;
10 }
11 triggerToast(status, msg) {
12 if (!status) return;
13 const nitroSelf = this,
14 toast_wrapper = $('.toast-wrapper').eq(0),
15 toast_text = toast_wrapper.find('.msg-box .text'),
16 toast_icon = toast_wrapper.find('.icon img');
17 var css_status = 'toast-' + status;
18
19 if (toast_wrapper.hasClass('shown')) {
20 //clone and hide prev toast
21 const clone = toast_wrapper.clone();
22 this.duplicateToast(clone, status, msg);
23 nitroSelf.hideToast(toast_wrapper);
24 } else {
25 //adjust text and show
26 toast_text.html(msg);
27 this.replaceIcon(status, toast_icon);
28 toast_wrapper.addClass('shown ' + css_status);
29 }
30 this.pauseAndHide(toast_wrapper);
31 }
32 pauseAndHide(toast_wrapper) {
33 const nitroSelf = this,
34 remainingTime = 1500;
35 var showedTime = Date.now(),
36 timeoutId,
37 currentRemaining = 1500;
38
39 timeoutId = setTimeout(function () {
40 nitroSelf.hideToast(toast_wrapper);
41 }, remainingTime);
42 //Pause timeout on mouse hover
43 toast_wrapper.on('mouseenter', function () {
44 nitroSelf.elapsedToastTime = Date.now() - showedTime;
45 clearTimeout(timeoutId);
46 });
47 //Resume timeout on mouse leave
48 toast_wrapper.on('mouseleave', function () {
49 showedTime = Date.now() - nitroSelf.elapsedToastTime; //track on multiple hover the correct showed time and apply to elapsedToastTime
50
51 currentRemaining = Math.max(remainingTime - nitroSelf.elapsedToastTime, 0); // Calculate remaining time
52
53 timeoutId = setTimeout(function () {
54 nitroSelf.hideToast(toast_wrapper);
55 }, currentRemaining);
56 });
57 }
58 duplicateToast(clone, status, msg) {
59 const toast_wrapper = $('.toast-wrapper');
60 var visible_toasts = $('.toast-wrapper.shown').length,
61 css_status = 'toast-' + status,
62 bottom = 8 + (5 * (visible_toasts - 1)), //multiply by 5, first is 8
63 toast_icon = clone.find('.icon img');
64
65 clone.find('.msg-box .text').html(msg);
66 this.replaceIcon(status, toast_icon);
67 this.hideToast(clone);
68
69 clone.insertBefore(toast_wrapper.eq(0));
70
71 setTimeout(function () {
72 clone.addClass(css_status + ' shown');
73
74 }, 250);
75 this.pauseAndHide(clone);
76 }
77 toastIcon(status) {
78 const icon = {
79 'error': 'alert-triangle',
80 'success': 'check-circle-green',
81 'info': 'info-circle-blue'
82 };
83 return icon[status];
84 }
85 replaceIcon(status, toast_icon) {
86 var new_icon = this.toastIcon(status),
87 icon_url = this.replaceIconNameInUrl(toast_icon.attr('src'), new_icon);
88 toast_icon.attr('src', icon_url);
89 }
90 replaceIconNameInUrl(url, newIconName) {
91 // Find the index of the last "/"
92 const lastSlashIndex = url.lastIndexOf('/');
93 // Find the index of the ".svg" extension
94 const svgIndex = url.indexOf('.svg', lastSlashIndex);
95 // Extract the icon name between the last "/" and ".svg"
96 const currentIconName = url.substring(lastSlashIndex + 1, svgIndex);
97 // Construct the new URL with the replaced icon name
98 const newUrl = url.replace(currentIconName + '.svg', newIconName + '.svg');
99
100 return newUrl;
101 }
102 closeToast() {
103 const nitroSelf = this;
104 $(document).on('click', '.toast-close', function () {
105 const el = $(this).closest('.toast-wrapper');
106 nitroSelf.hideToast(el)
107 });
108 }
109 hideToast(el) {
110 el.removeClass('shown toast-success toast-error toast-info');
111 }
112 //end of toasts
113 tabs() {
114 $('.tabs .tab-link').click(function () {
115 let tab = $(this).data('tab'),
116 tab_content_wrapper = $(this).closest('.tabs-wrapper').find('.tab-content-wrapper');
117 tab_content_wrapper.find('.tab-content').addClass('hidden');
118 tab_content_wrapper.find('.tab-content[data-tab="' + tab + '-tab"].hidden').removeClass('hidden');
119 });
120 }
121 highlight_columns() {
122 $('.modes .mode').on("mouseenter", function () {
123 var columnIndex = $(this).index(); // Get the index of the cell within its parent container
124 $(this).addClass('current-highlight')
125 $('.modes .mode:nth-child(' + (columnIndex + 1) + ')').addClass("highlight-column");
126 // Add the background class to all cells in the same column
127 }).on("mouseleave", function () {
128 $('.modes .mode').removeClass("highlight-column current-highlight");
129 // Remove the background class from all cells
130 });
131 }
132 toggle_submenu() {
133 $('.toggle-dropdown').click(function () {
134 let parent_li = $(this).closest('.list-item'),
135 child_ul = parent_li.find('ul'),
136 toggle_btn = $(this);
137 child_ul.toggleClass('opened');
138 toggle_btn.toggleClass('rotate-180');
139 });
140 }
141 posttype_taxonomy_counter() {
142 $('#modal-posttypes .taxonomies label input').click(function () {
143 var parent_li = $(this).closest('.sub-menu').parent('.list-item'),
144 counter_div = parent_li.find('.count'),
145 counter = counter_div.text() * 1;
146 if ($(this).is(':checked')) {
147 counter++
148 } else {
149 counter--
150 }
151 counter_div.text(counter);
152 });
153 }
154 cosmetics() {
155 $('.tooltip-container').removeClass('hidden');
156 }
157
158 }
159 const NitropackUI = new nitropackUI();
160 window.NitropackUI = NitropackUI;
161 });