admin_bar_menu.js
4 months ago
elementor_cache_integration.js
5 months ago
gravity_forms.js
2 months ago
math_captcha.js
1 year ago
nitropackUI.js
2 months ago
np_notices.js
3 months ago
np_safemode.js
1 year ago
np_select2.js
2 months ago
np_select2.min.js
2 months ago
np_settings.js
2 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
2 months ago
nitropackUI.js
307 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 | var backdrop = el.getAttribute('data-modal-backdrop') || 'dynamic'; |
| 94 | new Modal(el, { backdrop: backdrop }); |
| 95 | }); |
| 96 | |
| 97 | // data-modal-show |
| 98 | document.querySelectorAll('[data-modal-show]').forEach(function (trigger) { |
| 99 | var id = trigger.getAttribute('data-modal-show'); |
| 100 | trigger.addEventListener('click', function () { |
| 101 | var inst = instances[id]; |
| 102 | if (inst) inst.show(); |
| 103 | }); |
| 104 | }); |
| 105 | |
| 106 | // data-modal-hide |
| 107 | document.querySelectorAll('[data-modal-hide]').forEach(function (trigger) { |
| 108 | var id = trigger.getAttribute('data-modal-hide'); |
| 109 | trigger.addEventListener('click', function () { |
| 110 | var inst = instances[id]; |
| 111 | if (inst) inst.hide(); |
| 112 | }); |
| 113 | }); |
| 114 | |
| 115 | // data-modal-toggle |
| 116 | document.querySelectorAll('[data-modal-toggle]').forEach(function (trigger) { |
| 117 | var id = trigger.getAttribute('data-modal-toggle'); |
| 118 | |
| 119 | trigger.addEventListener('click', function () { |
| 120 | var inst = instances[id]; |
| 121 | if (inst) inst.toggle(); |
| 122 | }); |
| 123 | }); |
| 124 | |
| 125 | // .close-modal buttons — close the closest .modal-wrapper |
| 126 | document.querySelectorAll('.close-modal').forEach(function (btn) { |
| 127 | btn.addEventListener('click', function () { |
| 128 | var wrapper = btn.closest('.modal-wrapper'); |
| 129 | if (wrapper && wrapper.id && instances[wrapper.id]) { |
| 130 | instances[wrapper.id].hide(); |
| 131 | } |
| 132 | }); |
| 133 | }); |
| 134 | } |
| 135 | |
| 136 | window.Modal = Modal; |
| 137 | window.initModals = initModals; |
| 138 | |
| 139 | if (document.readyState === 'loading') { |
| 140 | document.addEventListener('DOMContentLoaded', initModals); |
| 141 | } else { |
| 142 | initModals(); |
| 143 | } |
| 144 | })(); |
| 145 | |
| 146 | jQuery(document).ready(function ($) { |
| 147 | class nitropackUI { |
| 148 | constructor() { |
| 149 | this.closeToast(); |
| 150 | this.highlight_columns(); |
| 151 | this.cosmetics(); |
| 152 | |
| 153 | //toasts |
| 154 | this.elapsedToastTime = 0; |
| 155 | } |
| 156 | triggerToast(status, msg) { |
| 157 | if (!status) return; |
| 158 | const nitroSelf = this, |
| 159 | toast_wrapper = $('.toast-wrapper').eq(0), |
| 160 | toast_text = toast_wrapper.find('.msg-box .text'), |
| 161 | toast_icon = toast_wrapper.find('.icon img'); |
| 162 | var css_status = 'toast-' + status; |
| 163 | |
| 164 | if (toast_wrapper.hasClass('shown')) { |
| 165 | //clone and hide prev toast |
| 166 | const clone = toast_wrapper.clone(); |
| 167 | this.duplicateToast(clone, status, msg); |
| 168 | nitroSelf.hideToast(toast_wrapper); |
| 169 | } else { |
| 170 | //adjust text and show |
| 171 | toast_text.html(msg); |
| 172 | this.replaceIcon(status, toast_icon); |
| 173 | toast_wrapper.addClass('shown ' + css_status); |
| 174 | } |
| 175 | this.pauseAndHide(toast_wrapper); |
| 176 | } |
| 177 | pauseAndHide(toast_wrapper) { |
| 178 | const nitroSelf = this, |
| 179 | remainingTime = 1500; |
| 180 | var showedTime = Date.now(), |
| 181 | timeoutId, |
| 182 | currentRemaining = 1500; |
| 183 | |
| 184 | timeoutId = setTimeout(function () { |
| 185 | nitroSelf.hideToast(toast_wrapper); |
| 186 | }, remainingTime); |
| 187 | //Pause timeout on mouse hover |
| 188 | toast_wrapper.on('mouseenter', function () { |
| 189 | nitroSelf.elapsedToastTime = Date.now() - showedTime; |
| 190 | clearTimeout(timeoutId); |
| 191 | }); |
| 192 | //Resume timeout on mouse leave |
| 193 | toast_wrapper.on('mouseleave', function () { |
| 194 | showedTime = Date.now() - nitroSelf.elapsedToastTime; //track on multiple hover the correct showed time and apply to elapsedToastTime |
| 195 | |
| 196 | currentRemaining = Math.max(remainingTime - nitroSelf.elapsedToastTime, 0); // Calculate remaining time |
| 197 | |
| 198 | timeoutId = setTimeout(function () { |
| 199 | nitroSelf.hideToast(toast_wrapper); |
| 200 | }, currentRemaining); |
| 201 | }); |
| 202 | } |
| 203 | duplicateToast(clone, status, msg) { |
| 204 | const toast_wrapper = $('.toast-wrapper'); |
| 205 | var visible_toasts = $('.toast-wrapper.shown').length, |
| 206 | css_status = 'toast-' + status, |
| 207 | bottom = 8 + (5 * (visible_toasts - 1)), //multiply by 5, first is 8 |
| 208 | toast_icon = clone.find('.icon img'); |
| 209 | |
| 210 | clone.find('.msg-box .text').html(msg); |
| 211 | this.replaceIcon(status, toast_icon); |
| 212 | this.hideToast(clone); |
| 213 | |
| 214 | clone.insertBefore(toast_wrapper.eq(0)); |
| 215 | |
| 216 | setTimeout(function () { |
| 217 | clone.addClass(css_status + ' shown'); |
| 218 | |
| 219 | }, 250); |
| 220 | this.pauseAndHide(clone); |
| 221 | } |
| 222 | toastIcon(status) { |
| 223 | const icon = { |
| 224 | 'error': 'alert-triangle', |
| 225 | 'success': 'check-circle-green', |
| 226 | 'info': 'info-circle-blue' |
| 227 | }; |
| 228 | return icon[status]; |
| 229 | } |
| 230 | replaceIcon(status, toast_icon) { |
| 231 | var new_icon = this.toastIcon(status), |
| 232 | icon_url = this.replaceIconNameInUrl(toast_icon.attr('src'), new_icon); |
| 233 | toast_icon.attr('src', icon_url); |
| 234 | } |
| 235 | replaceIconNameInUrl(url, newIconName) { |
| 236 | // Find the index of the last "/" |
| 237 | const lastSlashIndex = url.lastIndexOf('/'); |
| 238 | // Find the index of the ".svg" extension |
| 239 | const svgIndex = url.indexOf('.svg', lastSlashIndex); |
| 240 | // Extract the icon name between the last "/" and ".svg" |
| 241 | const currentIconName = url.substring(lastSlashIndex + 1, svgIndex); |
| 242 | // Construct the new URL with the replaced icon name |
| 243 | const newUrl = url.replace(currentIconName + '.svg', newIconName + '.svg'); |
| 244 | |
| 245 | return newUrl; |
| 246 | } |
| 247 | closeToast() { |
| 248 | const nitroSelf = this; |
| 249 | $(document).on('click', '.toast-close', function () { |
| 250 | const el = $(this).closest('.toast-wrapper'); |
| 251 | nitroSelf.hideToast(el) |
| 252 | }); |
| 253 | } |
| 254 | hideToast(el) { |
| 255 | el.removeClass('shown toast-success toast-error toast-info'); |
| 256 | } |
| 257 | //end of toasts |
| 258 | tabs() { |
| 259 | $('.tabs .tab-link').click(function () { |
| 260 | let tab = $(this).data('tab'), |
| 261 | tab_content_wrapper = $(this).closest('.tabs-wrapper').find('.tab-content-wrapper'); |
| 262 | tab_content_wrapper.find('.tab-content').addClass('hidden'); |
| 263 | tab_content_wrapper.find('.tab-content[data-tab="' + tab + '-tab"].hidden').removeClass('hidden'); |
| 264 | }); |
| 265 | } |
| 266 | highlight_columns() { |
| 267 | $('.modes .mode').on("mouseenter", function () { |
| 268 | var columnIndex = $(this).index(); // Get the index of the cell within its parent container |
| 269 | $(this).addClass('current-highlight') |
| 270 | $('.modes .mode:nth-child(' + (columnIndex + 1) + ')').addClass("highlight-column"); |
| 271 | // Add the background class to all cells in the same column |
| 272 | }).on("mouseleave", function () { |
| 273 | $('.modes .mode').removeClass("highlight-column current-highlight"); |
| 274 | // Remove the background class from all cells |
| 275 | }); |
| 276 | } |
| 277 | toggle_submenu() { |
| 278 | $('.toggle-dropdown').click(function () { |
| 279 | let parent_li = $(this).closest('.list-item'), |
| 280 | child_ul = parent_li.find('ul'), |
| 281 | toggle_btn = $(this); |
| 282 | child_ul.toggleClass('opened'); |
| 283 | toggle_btn.toggleClass('rotate-180'); |
| 284 | }); |
| 285 | } |
| 286 | posttype_taxonomy_counter() { |
| 287 | $('#modal-posttypes .taxonomies label input').click(function () { |
| 288 | var parent_li = $(this).closest('.sub-menu').parent('.list-item'), |
| 289 | counter_div = parent_li.find('.count'), |
| 290 | counter = counter_div.text() * 1; |
| 291 | if ($(this).is(':checked')) { |
| 292 | counter++ |
| 293 | } else { |
| 294 | counter-- |
| 295 | } |
| 296 | counter_div.text(counter); |
| 297 | }); |
| 298 | } |
| 299 | cosmetics() { |
| 300 | $('.tooltip-container').removeClass('hidden'); |
| 301 | } |
| 302 | |
| 303 | |
| 304 | } |
| 305 | const NitropackUI = new nitropackUI(); |
| 306 | window.NitropackUI = NitropackUI; |
| 307 | }); |