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
np_notices.js
102 lines
| 1 | (function () { |
| 2 | function updateNotificationCount() { |
| 3 | let notificationsCount = null; |
| 4 | let notificationsCountContainer = |
| 5 | document.getElementsByClassName("is-dismissible"); |
| 6 | |
| 7 | if (notificationsCountContainer) |
| 8 | notificationsCount = notificationsCountContainer.length; |
| 9 | |
| 10 | /* Admin bar update - NitroPack menu */ |
| 11 | let totalIssues = document.getElementById("nitro-total-issues-count"); |
| 12 | totalIssues.innerHTML = parseInt(totalIssues.innerHTML) - 1; |
| 13 | if (parseInt(totalIssues.innerHTML) === 0) totalIssues.remove(); |
| 14 | |
| 15 | /* settings sub menu count update */ |
| 16 | let notificationIssues = document.getElementById( |
| 17 | "nitro-notification-issues-count" |
| 18 | ); |
| 19 | notificationIssues.innerHTML = parseInt(notificationIssues.innerHTML) - 1; |
| 20 | if (parseInt(notificationIssues.innerHTML) === 0) |
| 21 | notificationIssues.remove(); |
| 22 | } |
| 23 | |
| 24 | /* Dismiss by setting a transient - used for notifications from the app */ |
| 25 | document.addEventListener( |
| 26 | "click", |
| 27 | function (e) { |
| 28 | if (e.target.matches(".dismiss-by-transient .btn-dismiss")) { |
| 29 | const xhr = new XMLHttpRequest(); |
| 30 | const data = new FormData(); |
| 31 | data.append("action", "nitropack_dismiss_notification_by_transient"); |
| 32 | data.append("nonce", nitropack_notices_vars.nonce); |
| 33 | data.append("notification_id", e.target.dataset.notification_id); |
| 34 | data.append("notification_end", e.target.dataset.notification_end); |
| 35 | data.append("dismiss_url", e.target.dataset.dismissUrl || ""); |
| 36 | |
| 37 | xhr.onreadystatechange = function () { |
| 38 | if (xhr.readyState === XMLHttpRequest.DONE) { |
| 39 | if (xhr.status === 200) { |
| 40 | let response = JSON.parse(xhr.responseText); |
| 41 | if (response.status === true) { |
| 42 | let notificationElement = e.target.closest( |
| 43 | ".nitro-notification" |
| 44 | ); |
| 45 | |
| 46 | if (notificationElement) notificationElement.remove(); |
| 47 | |
| 48 | updateNotificationCount(); |
| 49 | } |
| 50 | } else { |
| 51 | console.error("Dismiss failed:", xhr.responseText); |
| 52 | } |
| 53 | } |
| 54 | }; |
| 55 | xhr.open("POST", ajaxurl); |
| 56 | xhr.send(data); |
| 57 | } |
| 58 | }, |
| 59 | true |
| 60 | ); |
| 61 | /* Dismiss permanently notification by updating wp_options */ |
| 62 | document.addEventListener( |
| 63 | "click", |
| 64 | function (e) { |
| 65 | if (e.target.matches(".dismiss-by-option .btn-dismiss")) { |
| 66 | const dismissButton = e.target; |
| 67 | const dismissId = dismissButton.dataset.dismissibleId; |
| 68 | if (!dismissId) return; |
| 69 | |
| 70 | const noticeElement = dismissButton.closest(".nitro-notification"); |
| 71 | const data = new FormData(); |
| 72 | data.append("action", "nitropack_dismiss_permanently_notification"); |
| 73 | data.append("nonce", nitropack_notices_vars.nonce); |
| 74 | data.append("notification_id", dismissId); |
| 75 | |
| 76 | const xhr = new XMLHttpRequest(); |
| 77 | xhr.onreadystatechange = function () { |
| 78 | if (xhr.readyState === XMLHttpRequest.DONE) { |
| 79 | try { |
| 80 | const response = JSON.parse(xhr.responseText); |
| 81 | if (xhr.status === 200 && response.success) { |
| 82 | noticeElement?.remove(); |
| 83 | } else { |
| 84 | console.error( |
| 85 | "Dismiss failed:", |
| 86 | response?.data?.message || "Unknown error" |
| 87 | ); |
| 88 | } |
| 89 | } catch (err) { |
| 90 | console.error("Failed to parse response:", err); |
| 91 | } |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | xhr.open("POST", ajaxurl); |
| 96 | xhr.send(data); |
| 97 | } |
| 98 | }, |
| 99 | true |
| 100 | ); |
| 101 | })(); |
| 102 |