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
1 year ago
np_safemode.js
2 years ago
np_settings.js
1 year ago
popper.min.js
4 years ago
widgets_ajax.js
3 years ago
np_notices.js
90 lines
| 1 | (function () { |
| 2 | /* Dismiss notification by cookie */ |
| 3 | document.addEventListener( |
| 4 | "click", |
| 5 | (event) => { |
| 6 | const dismissButton = event.target.closest( |
| 7 | ".nitro-notification.is-dismissible[data-dismissible-id] .btn-dismiss" |
| 8 | ); |
| 9 | |
| 10 | if (dismissButton) { |
| 11 | const noticeElement = dismissButton.closest( |
| 12 | ".nitro-notification.is-dismissible[data-dismissible-id]" |
| 13 | ); |
| 14 | |
| 15 | if (noticeElement) { |
| 16 | const noticeId = noticeElement.dataset.dismissibleId; |
| 17 | |
| 18 | if (noticeId) { |
| 19 | document.cookie = `dismissed_notice_${noticeId}=1; path=/; max-age=${ |
| 20 | 86400 * 30 |
| 21 | }; secure`; |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | }, |
| 26 | true |
| 27 | ); |
| 28 | |
| 29 | /* Dismiss by setting a transient - used for notifications from the app */ |
| 30 | document.addEventListener( |
| 31 | "click", |
| 32 | function (e) { |
| 33 | if (e.target.matches(".app-notification .btn-dismiss")) { |
| 34 | var xhr = new XMLHttpRequest(); |
| 35 | var data = new FormData(); |
| 36 | data.append("action", "nitropack_dismiss_notification"); |
| 37 | data.append("nonce", nitropack_notices_vars.nonce); |
| 38 | data.append("notification_id", e.target.dataset.notification_id); |
| 39 | data.append("notification_end", e.target.dataset.notification_end); |
| 40 | |
| 41 | xhr.onreadystatechange = function () { |
| 42 | if (xhr.readyState === XMLHttpRequest.DONE) { |
| 43 | if (xhr.status === 200) { |
| 44 | let response = JSON.parse(xhr.responseText); |
| 45 | if (response.transient_status === true) { |
| 46 | let notificationsCount = null; |
| 47 | let notificationElement = e.target.closest( |
| 48 | ".nitro-notification" |
| 49 | ); |
| 50 | |
| 51 | if (notificationElement) notificationElement.remove(); |
| 52 | |
| 53 | let notificationsCountContainer = |
| 54 | document.getElementById("app-notifications"); |
| 55 | if (notificationsCountContainer) |
| 56 | notificationsCount = |
| 57 | notificationsCountContainer.querySelectorAll("li").length; |
| 58 | |
| 59 | if (notificationsCount === 0) |
| 60 | document.getElementById("app-notifications").remove(); |
| 61 | |
| 62 | /* Admin bar update - NitroPack menu */ |
| 63 | let totalIssues = document.getElementById( |
| 64 | "nitro-total-issues-count" |
| 65 | ); |
| 66 | totalIssues.innerHTML = parseInt(totalIssues.innerHTML) - 1; |
| 67 | if (parseInt(totalIssues.innerHTML) === 0) totalIssues.remove(); |
| 68 | |
| 69 | /* settings sub menu count update */ |
| 70 | let notificationIssues = document.getElementById( |
| 71 | "nitro-notification-issues-count" |
| 72 | ); |
| 73 | notificationIssues.innerHTML = |
| 74 | parseInt(notificationIssues.innerHTML) - 1; |
| 75 | if (parseInt(notificationIssues.innerHTML) === 0) |
| 76 | notificationIssues.remove(); |
| 77 | } |
| 78 | } else { |
| 79 | console.log("Error: " + xhr.status); |
| 80 | } |
| 81 | } |
| 82 | }; |
| 83 | xhr.open("POST", ajaxurl); |
| 84 | xhr.send(data); |
| 85 | } |
| 86 | }, |
| 87 | true |
| 88 | ); |
| 89 | })(); |
| 90 |