-
Notifications
You must be signed in to change notification settings - Fork 38
/
alerts.js
105 lines (90 loc) · 2.47 KB
/
alerts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
* Copyright (c) 2019, Code Atlantic LLC
******************************************************************************/
(function($) {
"use strict";
var $alerts = $(".pum-alerts"),
$noticeCounts = $(".pum-alert-count"),
count = parseInt($noticeCounts.eq(0).text());
function dismissAlert($alert, alertAction) {
var dismissible = $alert.data("dismissible"),
expires =
dismissible === "1" || dismissible === 1 || dismissible === true
? null
: dismissible;
$.ajax({
method: "POST",
dataType: "json",
url: ajaxurl,
data: {
action: "pum_alerts_action",
nonce: window.pum_alerts_nonce,
code: $alert.data("code"),
expires: expires,
pum_dismiss_alert: alertAction
}
});
}
function dismissReviewRequest(reason) {
$.ajax({
method: "POST",
dataType: "json",
url: ajaxurl,
data: {
action: "pum_review_action",
nonce: window.pum_review_nonce,
group: window.pum_review_trigger.group,
code: window.pum_review_trigger.code,
pri: window.pum_review_trigger.pri,
reason: reason
}
});
if (typeof window.pum_review_api_url !== "undefined") {
$.ajax({
method: "POST",
dataType: "json",
url: window.pum_review_api_url,
data: {
trigger_group: window.pum_review_trigger.group,
trigger_code: window.pum_review_trigger.code,
reason: reason,
uuid: window.pum_review_uuid || null
}
});
}
}
function checkRemoveAlerts() {
if ($alerts.find(".pum-alert-holder").length === 0) {
$alerts.slideUp(100, function() {
$alerts.remove();
});
$("#menu-posts-popup .wp-menu-name .update-plugins").fadeOut();
}
}
function removeAlert($alert) {
count--;
$noticeCounts.text(count);
$alert.fadeTo(100, 0, function() {
$alert.slideUp(100, function() {
$alert.remove();
checkRemoveAlerts();
});
});
}
$(document)
.on("pumDismissAlert", checkRemoveAlerts)
.on("click", ".pum-alert-holder .pum-dismiss", function(event) {
var $this = $(this),
$alert = $this.parents(".pum-alert-holder"),
reason = $this.data("reason") || "maybe_later",
alertAction = $(this).data("action") || "dismiss";
// Prevent the PHP alert handler from also processing this.
event.preventDefault();
if ("review_request" !== $alert.data("code")) {
dismissAlert($alert, alertAction);
} else {
dismissReviewRequest(reason);
}
removeAlert($alert);
});
})(jQuery);