admin_bar_menu.js
1 year ago
flowbite.min.js
1 year ago
gravity_forms.js
1 year ago
math_captcha.js
1 year ago
metabox.js
1 year ago
nitropackUI.js
1 year ago
np_notices.js
1 year ago
np_safemode.js
1 year ago
np_settings.js
1 year ago
popper.min.js
1 year ago
widgets_ajax.js
1 year ago
np_notices.js
101 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 | |
| 36 | xhr.onreadystatechange = function () { |
| 37 | if (xhr.readyState === XMLHttpRequest.DONE) { |
| 38 | if (xhr.status === 200) { |
| 39 | let response = JSON.parse(xhr.responseText); |
| 40 | if (response.transient_status === true) { |
| 41 | let notificationElement = e.target.closest( |
| 42 | ".nitro-notification" |
| 43 | ); |
| 44 | |
| 45 | if (notificationElement) notificationElement.remove(); |
| 46 | |
| 47 | updateNotificationCount(); |
| 48 | } |
| 49 | } else { |
| 50 | console.log("Error: " + xhr.status); |
| 51 | } |
| 52 | } |
| 53 | }; |
| 54 | xhr.open("POST", ajaxurl); |
| 55 | xhr.send(data); |
| 56 | } |
| 57 | }, |
| 58 | true |
| 59 | ); |
| 60 | /* Dismiss permanently notification by updating wp_options */ |
| 61 | document.addEventListener( |
| 62 | "click", |
| 63 | function (e) { |
| 64 | if (e.target.matches(".dismiss-by-option .btn-dismiss")) { |
| 65 | const dismissButton = e.target; |
| 66 | const dismissId = dismissButton.dataset.dismissibleId; |
| 67 | if (!dismissId) return; |
| 68 | |
| 69 | const noticeElement = dismissButton.closest(".nitro-notification"); |
| 70 | const data = new FormData(); |
| 71 | data.append("action", "nitropack_dismiss_permanently_notification"); |
| 72 | data.append("nonce", nitropack_notices_vars.nonce); |
| 73 | data.append("notification_id", dismissId); |
| 74 | |
| 75 | const xhr = new XMLHttpRequest(); |
| 76 | xhr.onreadystatechange = function () { |
| 77 | if (xhr.readyState === XMLHttpRequest.DONE) { |
| 78 | try { |
| 79 | const response = JSON.parse(xhr.responseText); |
| 80 | if (xhr.status === 200 && response.success) { |
| 81 | noticeElement?.remove(); |
| 82 | } else { |
| 83 | console.error( |
| 84 | "Dismiss failed:", |
| 85 | response?.data?.message || "Unknown error" |
| 86 | ); |
| 87 | } |
| 88 | } catch (err) { |
| 89 | console.error("Failed to parse response:", err); |
| 90 | } |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | xhr.open("POST", ajaxurl); |
| 95 | xhr.send(data); |
| 96 | } |
| 97 | }, |
| 98 | true |
| 99 | ); |
| 100 | })(); |
| 101 |