-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlert.js
79 lines (62 loc) · 1.9 KB
/
Alert.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
export class Alert {
#alerts
#alertContent
#alertPlaceholder
#alertGenerated
constructor(alertPlaceholder) {
this.#alerts = {
"secure": ["success", "Password is secure"],
"insecure": ["danger", "Password is insecure"],
"copy": ["info", "Password copied to clipboard"],
"requirements": ["warning", [
"<ul>",
"<li>Require at least 15 total characters</li>",
"<li>Require at least 5 numerical characters</li>",
"<li>Require at least 3 capital letters</li>",
"<li>Require at least 2 lower letters</li>",
"<li>Special characters are optional</li>",
"</ul>"
].join("")]
}
this.#alertPlaceholder = alertPlaceholder
}
generateAlert(alertType) {
this.#clearAlert()
this.#setAlertContent(alertType)
this.#setAlertElement()
this.#alertPlaceholder.append(this.#alertGenerated)
}
#setAlertContent(alertType) {
this.#alertContent = this.#alerts[alertType]
}
#setAlertElement() {
const alertBody = this.#setAlertBody(),
alertMessage = this.#setAlertMessage(),
alertButton = this.#setAlertButton()
alertBody.append(alertMessage, alertButton)
this.#alertGenerated = alertBody
}
#setAlertBody() {
const alertBody = document.createElement("div")
alertBody.classList.add("alert", `alert-${this.#alertContent[0]}`, "alert-dismissible", "my-5")
alertBody.setAttribute("role", "alert")
return alertBody
}
#setAlertMessage() {
const alertMessage = document.createElement("span")
alertMessage.innerHTML = this.#alertContent[1]
return alertMessage
}
#setAlertButton() {
const alertButton = document.createElement("button")
alertButton.classList.add("btn-close")
alertButton.setAttribute("data-bs-dismiss", "alert")
alertButton.type = "button"
alertButton.ariaLabel = "Close"
return alertButton
}
#clearAlert() {
const lastChild = this.#alertPlaceholder.lastChild
if (lastChild != null) this.#alertPlaceholder.removeChild(lastChild)
}
}