Skip to content

Commit e6aaa0d

Browse files
Merge pull request #2 from aleksanderkoder/V3
V3
2 parents 2f49ccb + 60e5468 commit e6aaa0d

File tree

3 files changed

+107
-35
lines changed

3 files changed

+107
-35
lines changed

OzoneAlerts.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
background-color: rgba(0, 0, 0, 0.75);
1919
font-family: "Roboto";
2020
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
21-
animation: ozfadeIn ease 0.5s;
21+
animation: ozFadeIn ease 0.25s;
2222
z-index: 999999;
2323
}
2424

@@ -42,7 +42,7 @@
4242
}
4343

4444
/* Styles the buttons used for the dialog type */
45-
#OzoneBtnConfirm {
45+
.OzoneBtnConfirm {
4646
margin-right: 30px;
4747
transition: 0.3s;
4848
border-radius: 2px;
@@ -55,13 +55,13 @@
5555
cursor: pointer;
5656
}
5757

58-
#OzoneBtnConfirm:hover {
58+
.OzoneBtnConfirm:hover {
5959
background-color: rgba(37, 155, 53, 0.75);
6060
color: white;
6161
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
6262
}
6363

64-
#OzoneBtnCancel {
64+
.OzoneBtnCancel {
6565
margin-left: 30px;
6666
transition: 0.3s;
6767
border-radius: 2px;
@@ -74,7 +74,7 @@
7474
cursor: pointer;
7575
}
7676

77-
#OzoneBtnCancel:hover {
77+
.OzoneBtnCancel:hover {
7878
background-color: rgba(155, 37, 37, 0.75);
7979
color: white;
8080
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
@@ -86,7 +86,7 @@
8686
}
8787

8888
/* Specifies animations used upon initial appearance, persisting and deletion of alert */
89-
@keyframes ozfadeIn {
89+
@keyframes ozFadeIn {
9090
0% {
9191
opacity: 0;
9292
}
@@ -96,7 +96,7 @@
9696
}
9797
}
9898

99-
@keyframes ozfadeOut {
99+
@keyframes ozFadeOut {
100100
0% {
101101
opacity: 1;
102102
}
@@ -106,7 +106,7 @@
106106
}
107107
}
108108

109-
@keyframes ozpulse {
109+
@keyframes ozPulse {
110110
0% {
111111
box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.7);
112112
}

OzoneAlerts.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class Ozone {
44
message,
55
position,
66
type = "notification",
7-
confirmButtonText = "Confirm",
8-
cancelButtonText = "Cancel",
7+
options = {},
98
onConfirm = function () {},
109
onCancel = function () {}
1110
) {
@@ -26,11 +25,11 @@ class Ozone {
2625

2726
// Handles icon selection based on parameter "icon"
2827
if (icon == "success") {
29-
divIcon.innerHTML = '<i style=" color: white;" class="fas fa-check"></i>';
28+
divIcon.innerHTML = '<i class="fas fa-check"></i>';
3029
} else if (icon == "error") {
31-
divIcon.innerHTML = '<i style="color: white;" class="fas fa-times"></i>';
30+
divIcon.innerHTML = '<i class="fas fa-times"></i>';
3231
} else if (icon == "info") {
33-
divIcon.innerHTML = '<i style="color: white;" class="fas fa-info"></i>';
32+
divIcon.innerHTML = '<i class="fas fa-info"></i>';
3433
}
3534
// Creates Ozone instance of type "dialog" based on "type" parameter
3635
if (type == "dialog") {
@@ -45,11 +44,11 @@ class Ozone {
4544
divControls.className = "OzoneControls";
4645

4746
const btnConfirm = document.createElement("button");
48-
btnConfirm.id = "OzoneBtnConfirm";
49-
btnConfirm.innerHTML = confirmButtonText;
47+
btnConfirm.className = "OzoneBtnConfirm";
48+
btnConfirm.innerHTML = "Confirm";
5049
const btnCancel = document.createElement("button");
51-
btnCancel.id = "OzoneBtnCancel";
52-
btnCancel.innerHTML = cancelButtonText;
50+
btnCancel.className = "OzoneBtnCancel";
51+
btnCancel.innerHTML = "Cancel";
5352

5453
// Appends elements to parent element
5554
el.appendChild(divControls);
@@ -66,6 +65,28 @@ class Ozone {
6665
onCancel();
6766
removeOzoneAlert(el);
6867
};
68+
69+
// Sets dialog specific options based on "options" object parameter
70+
if(Object.keys(options).length > 0) {
71+
if(options.confirmButtonText) {
72+
btnConfirm.innerHTML = options.confirmButtonText;
73+
}
74+
if(options.cancelButtonText) {
75+
btnCancel.innerHTML = options.cancelButtonText;
76+
}
77+
if(options.confirmButtonColor) {
78+
btnConfirm.style.backgroundColor = options.confirmButtonColor;
79+
}
80+
if(options.cancelButtonColor) {
81+
btnCancel.style.backgroundColor = options.cancelButtonColor;
82+
}
83+
if(options.confirmButtonRadius) {
84+
btnConfirm.style.borderRadius = options.confirmButtonRadius;
85+
}
86+
if(options.cancelButtonRadius) {
87+
btnCancel.style.borderRadius = options.cancelButtonRadius;
88+
}
89+
}
6990
}
7091

7192
// Handles position based on parameter "position"
@@ -114,18 +135,37 @@ class Ozone {
114135
break;
115136
}
116137

117-
// Handles animations upon creation and deletion of Ozone element
118-
setTimeout(() => {
119-
el.style.animation = "ozpulse 2s infinite";
120-
}, 1000);
138+
// Sets general options based on "options" object passed as parameter
139+
if(Object.keys(options).length > 0) {
140+
if(options.backgroundColor) {
141+
el.style.backgroundColor = options.backgroundColor;
142+
}
143+
if(options.fontColor) {
144+
divMessage.style.color = options.fontColor;
145+
}
146+
if(options.iconColor) {
147+
divIcon.style.color = options.iconColor;
148+
}
149+
if(options.borderRadius) {
150+
el.style.borderRadius = options.borderRadius;
151+
}
152+
if(options.border) {
153+
el.style.border = options.border;
154+
}
155+
}
121156

122157
// Finally appends Ozone alert element to document body
123158
document.body.appendChild(el);
124159

160+
// Handles animations upon creation and deletion of Ozone element
161+
setTimeout(() => {
162+
el.style.animation = "ozPulse 2s infinite";
163+
}, 1000);
164+
125165
// Handles behavior of Ozone alert upon deletion based on type
126166
if (type == "notification") {
127167
setTimeout(() => {
128-
el.style.animation = "ozfadeOut ease 1s";
168+
el.style.animation = "ozFadeOut ease 1s";
129169
}, 7000);
130170

131171
setTimeout(() => {
@@ -135,10 +175,10 @@ class Ozone {
135175

136176
// Function that removes a given Ozone-element with a fadeOut-effect
137177
function removeOzoneAlert(element) {
138-
element.style.animation = "ozfadeOut ease 0.5s";
178+
element.style.animation = "ozFadeOut ease 0.5s";
139179
setTimeout(() => {
140180
element.parentNode.removeChild(element);
141-
}, 500);
181+
}, 495);
142182
}
143183
}
144184
}

README.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,26 @@ OzoneAlerts.js should now be ready for use.
2626

2727
Basic usage:
2828
```javascript
29-
Ozone.fire("success", "Hello, world!", "top-left")
29+
Ozone.fire("success", "Hello, world!", "top-left");
3030
```
3131
Advanced usage:
3232
```javascript
33-
Ozone.fire("success", "Would you like a cinnamon roll?", "top-left", "dialog", "Yes thanks!", "No thanks!",
33+
let options = {backgroundColor: "green", fontColor: "#8b0000"};
34+
35+
Ozone.fire("success", "Would you like a cinnamon roll?", "top-left", "dialog", options,
3436
function () {
3537
alert("You just pressed the confirm button!")},
3638
function () {
3739
alert("You just pressed the cancel button!")}
38-
)
40+
);
3941
```
4042

4143

4244
***Parameters***
4345

4446
Method parameter structure:
4547
```javascript
46-
Ozone.fire(icon, message, position, type, confirmButtonText, cancelButtonText, onConfirm, onCancel)
48+
Ozone.fire(icon, message, position, type, options, onConfirm, onCancel);
4749
```
4850

4951
*The first three parameters are required.*
@@ -68,19 +70,49 @@ The fourth parameter *"type"* (optional) chooses what type of alert should be sh
6870
1. "notification" - (default) The standard slim variant.
6971
2. "dialog" - The full-sized variant allowing user input via programmable buttons.
7072

71-
The fifth parameter *"confirmButtonText"* (optional) sets the text shown inside the "confirm" dialog button.
72-
- Example value: "I got it!"
73+
The fifth parameter *"options"* (optional) is an object containing different properties which are used to configure the alert visually. Create an object containing the options you want and pass it as a parameter to the *Ozone.fire()* method.
74+
An example of the options object:
7375

74-
The sixt parameter *"cancelButtonText"* (optional) sets the text shown inside the "cancel" dialog button.
75-
- Example value: "No thanks!"
76+
```javascript
77+
let options = {backgroundColor: "green", fontColor: "#8b0000"};
78+
```
7679

77-
The seventh and eight parameters *"onConfirm"* (optional) and *"onCancel"* (optional) controls what should happen when each of the two dialog buttons are pressed.
78-
These parameters take a function containing whatever code you want.
80+
The sixt and seventh parameters *"onConfirm"* (optional) and *"onCancel"* (optional) controls what should happen when each of the two dialog buttons are pressed.
81+
These parameters take a function containing whatever code you want. If no code is provided and the buttons are clicked, the button will close the dialog only.
7982
- See the "advanced usage" example under the *Usage* section for an exact example of how these parameters can be used.
8083

8184
## Visual customization
8285

83-
The alerts can be easily customized via the *OzoneAlerts.css* style sheet. This requires basic knowledge of CSS, however.
86+
**OzoneAlerts.js** can be visually customized using the *"options"* parameter, using an object containing the wanted properties. These options are split into two categories. One that is relevant for both types ("notification" and "dialog"), and one that is only applied for the "dialog" type alert. All standard CSS values are valid for the specified properties.
87+
88+
The general customization options available are:
89+
1. **backgroundColor** - Sets the "background-color" CSS property for the alert element.
90+
- Example value: "green", "#8b0000" etc.
91+
2. **fontColor** - Sets the "font-color" CSS property for the alert element.
92+
- Example value: "red", "#FFFF00" etc.
93+
3. **iconColor** - Sets the color CSS property for the icon in the alert element.
94+
- Example value: "black", "#000000" etc.
95+
4. **borderRadius** - Sets the "border-radius" CSS property for the alert element.
96+
- Example value: "5px"
97+
5. **border** - Sets the "border" CSS property for the alert element.
98+
- Example value: "5px solid white"
99+
100+
The "dialog" specific customization options available are:
101+
1. **confirmButtonText** - Sets the inner text of the confirmation button.
102+
- Example value: "Hello, world!"
103+
2. **cancelButtonText** - Sets the inner text of the cancellation button.
104+
- Example value: "Goodbye, world!"
105+
3. **confirmButtonColor** - Sets the "background-color" CSS property for the confirmation button.
106+
- Example value: "green", "#8b0000" etc.
107+
4. **cancelButtonColor** - Sets the "background-color" CSS property for the cancellation button.
108+
- Example value: "red", "#008080" etc.
109+
5. **confirmButtonRadius** - Sets the "border-radius" CSS property for the confirmation button.
110+
- Example value: "5px"
111+
6. **cancelButtonRadius** - Sets the "border-radius" CSS property for the cancellation button.
112+
- Example value: "15px"
113+
114+
115+
If you require more control over the visuals, the alerts can be customized via the *OzoneAlerts.css* style sheet. This requires basic knowledge of CSS, however.
84116

85117
## Dependencies
86118
- Font Awesome (https://fontawesome.com/) - Needed for icons to appear. Include it within the head tag of your HTML.

0 commit comments

Comments
 (0)