Skip to content

Commit bc90a1b

Browse files
committed
moved all inline css to external css, updated confirm message, positioned and fixed modal
1 parent f4004f1 commit bc90a1b

File tree

6 files changed

+320
-167
lines changed

6 files changed

+320
-167
lines changed

dist/alertify.js

Lines changed: 63 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,96 +32,86 @@ var AlertNotify = (function () {
3232
"position property is invalid choose between: center,bottom-center,bottom-right,bottom-left,top-center,top-left,top-right"
3333
);
3434
this.position = position;
35-
if (this.position == "top-right")
36-
this.placement = "right: 2%; top: 2%; z-index:1000000";
37-
if (this.position == "top-left")
38-
this.placement = "left: 2%; top: 2%; z-index:1000000";
39-
if (this.position == "top-center")
40-
this.placement =
41-
"top: 4%; left: 50%; transform: translate(-50%, -50%); z-index:1000000";
42-
if (this.position == "center")
43-
this.placement =
44-
"top: 50%; left: 50%; transform: translate(-50%, -50%); z-index:1000000";
45-
if (this.position == "bottom-left")
46-
this.placement = "left: 2%; bottom: 2%; z-index:1000000";
47-
if (this.position == "bottom-right")
48-
this.placement = "right: 2%; bottom: 2%; z-index:1000000";
49-
if (this.position == "bottom-center")
50-
this.placement =
51-
"bottom: 5%; left: 50%; transform: translate(-50%, -50%); z-index:1000000";
35+
if (this.position == "top-right") this.placement = "top-right";
36+
if (this.position == "top-left") this.placement = "top-left";
37+
if (this.position == "top-center") this.placement = "top-center";
38+
if (this.position == "center") this.placement = "center";
39+
if (this.position == "bottom-left") this.placement = "bottom-left";
40+
if (this.position == "bottom-right") this.placement = "bottom-right";
41+
if (this.position == "bottom-center") this.placement = "bottom-center";
5242
this.notifyBox.addEventListener("click", (e) => {
5343
e.preventDefault();
5444
this.hideOnClick();
5545
});
5646
this.hideModal();
5747
}
5848

59-
alert_message(msg = "", type = "", use = "fixed-modal") {
49+
alert_message(msg = "", type = "", use = "fixed-modal", action = "Okay!") {
6050
const msgBox = `${msg}`;
6151
if (use == "fixed-modal") {
6252
switch (type) {
6353
case "success":
6454
document.body.appendChild(this.modalBox);
6555
this.modalBox.innerHTML = `
66-
<div class="modal-div">
67-
<span style="background:#23c55e;color:#000">&check;</span>
56+
<div class="nonny-modal-div nm-success">
57+
<span>&check;</span>
6858
<h2>Success!</h2>
6959
<p>
7060
${msg}
7161
</p>
72-
<button class="close-nonny-modal" style="background:#23c55e;color:#000">Okay!</button>
62+
<button class="close-nonny-modal">${action}</button>
7363
</div>`;
7464
this.showModal();
7565
break;
7666
case "warning":
7767
document.body.appendChild(this.modalBox);
7868
this.modalBox.innerHTML = `
79-
<div class="modal-div">
80-
<span style="background:#feb601;color:#000">&#x26A0;</span>
69+
<div class="nonny-modal-div nm-warning">
70+
<span>&#x26A0;</span>
8171
<h2>Warning!</h2>
8272
<p>
8373
${msg}
8474
</p>
85-
<button class="close-nonny-modal" style="background:#feb601;color:#000">Okay!</button>
75+
<button class="close-nonny-modal">${action}</button>
8676
</div>`;
8777
this.showModal();
8878
break;
8979
case "info":
9080
document.body.appendChild(this.modalBox);
9181
this.modalBox.innerHTML = `
92-
<div class="modal-div">
93-
<span style="background:hsl(241, 93%, 29%);color:#fff;">&#9432;</span>
82+
<div class="nonny-modal-div nm-info">
83+
<span>&#9432;</span>
9484
<h2>Info!</h2>
9585
<p>
9686
${msg}
9787
</p>
98-
<button class="close-nonny-modal" style="background:hsl(241, 93%, 29%);color:#fff;">Okay!</button>
88+
<button class="close-nonny-modal">${action}</button>
9989
</div>`;
10090
this.showModal();
10191
break;
10292
case "danger":
10393
document.body.appendChild(this.modalBox);
10494
this.modalBox.innerHTML = `
105-
<div class="modal-div">
106-
<span style="background:#eb5f51;color:#000;">&times;</span>
95+
<div class="nonny-modal-div nm-danger">
96+
<span>&times;</span>
10797
<h2>Danger!</h2>
10898
<p>
10999
${msg}
110100
</p>
111-
<button class="close-nonny-modal" style="background:#eb5f51;color:#000;">Okay!</button>
101+
<button class="close-nonny-modal">${action}</button>
112102
</div>`;
113103
this.showModal();
114104
break;
115105
default:
116106
document.body.appendChild(this.modalBox);
117107
this.modalBox.innerHTML = `
118-
<div class="modal-div">
119-
<span style="background:#24282f;color#fff;">&#63;</span>
108+
<div class="nonny-modal-div nm-default">
109+
<span>&#63;</span>
120110
<h2>Default!</h2>
121111
<p>
122112
${msg}
123113
</p>
124-
<button class="close-nonny-modal" style="background:#24282f;color#fff;">Okay!</button>
114+
<button class="close-nonny-modal">${action}</button>
125115
</div>`;
126116
this.showModal();
127117
break;
@@ -131,52 +121,42 @@ var AlertNotify = (function () {
131121
switch (type) {
132122
case "success":
133123
document.body.appendChild(this.notifyBox);
134-
this.notifyBox.style = `position: fixed;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;background: #23c55e; color: #000;max-width:400px;padding: 10px; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19);${this.placement}; border: 2px solid #ddd;word-wrap:break-word;cursor:pointer;gap:1rem;`;
135-
this.notifyBox.innerHTML = `<b style="display:flex;justify-content:center;align-items:center;width:30px;height:30px; border-radius:50%;background:#fff;color:#000;font-weight:800">&check;</b><p style="flex:1;width:-moz-fit-content;width:fit-content; padding:0 0 6px 0; color: inherit;font-size:18px;font-weight:500;line-height:20px;cursor:pointer;">${msgBox}</p>`;
124+
this.notifyBox.classList.add("nm-success", this.placement);
125+
this.notifyBox.innerHTML = `<b>&check;</b><p>${msgBox}</p>`;
136126
alertLoader = document.createElement("span");
137-
alertLoader.setAttribute("id", "alertLoader");
138-
alertLoader.style =
139-
"position:absolute;width:100%;height:6px;background:linear-gradient(90deg,rgb(92, 66, 208),rgb(82, 75, 122)); border-radius:12px;left:0;bottom:0;transition:all 2s;";
127+
alertLoader.setAttribute("class", "nonny-alertLoader");
140128
this.notifyBox.appendChild(alertLoader);
141129
break;
142130
case "danger":
143131
document.body.appendChild(this.notifyBox);
144-
this.notifyBox.style = `position: fixed;background: #f44336;display:flex;flex-wrap:wrap;justify-content:center;align-items:center; max-width:400px; color: #fff;padding: 10px; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19);${this.placement};border: 2px solid #ddd; word-wrap:break-word;cursor:pointer;gap:1rem`;
145-
this.notifyBox.innerHTML = `<b style="display:flex;justify-content:center;align-items:center;width:30px;height:30px; border-radius:50%;background:#fff;color:#000;font-weight:800">&times;</b><p style="flex:1;width:fit-content; padding:0 0 6px 0; color: inherit;font-size:18px;font-weight:500;line-height:20px;cursor:pointer;"> ${msgBox}</p>`;
132+
this.notifyBox.classList.add("nm-danger", this.placement);
133+
this.notifyBox.innerHTML = `<b>&times;</b><p>${msgBox}</p>`;
146134
alertLoader = document.createElement("span");
147-
alertLoader.setAttribute("id", "alertLoader");
148-
alertLoader.style =
149-
"position:absolute;width:100%;height:6px;background:linear-gradient(90deg,rgb(92, 66, 208),rgb(82, 75, 122)); border-radius:12px;left:0;bottom:0;transition:all 2s;";
135+
alertLoader.setAttribute("class", "nonny-alertLoader");
150136
this.notifyBox.appendChild(alertLoader);
151137
break;
152138
case "warning":
153139
document.body.appendChild(this.notifyBox);
154-
this.notifyBox.style = `position: fixed;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;max-width:400px;background: #feb601; color: #000;padding: 10px; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19); ${this.placement};border: 2px solid #ddd;word-wrap:break-word;cursor:pointer;gap:1rem`;
155-
this.notifyBox.innerHTML = `<b style="display:flex;justify-content:center;align-items:center;width:30px;height:30px; border-radius:50%;background:#fff;color:#000;font-weight:800">&#x26A0;</b><p style="flex:1;width:-moz-fit-content;width:fit-content; padding:0 0 6px 0; color: inherit;font-size:18px;font-weight:500;line-height:20px;cursor:pointer;"> ${msgBox}</p>`;
140+
this.notifyBox.classList.add("nm-warning", this.placement);
141+
this.notifyBox.innerHTML = `<b>&#x26A0;</b><p>${msgBox}</p>`;
156142
alertLoader = document.createElement("span");
157-
alertLoader.setAttribute("id", "alertLoader");
158-
alertLoader.style =
159-
"position:absolute;width:100%;height:6px;background:linear-gradient(90deg,rgb(92, 66, 208),rgb(82, 75, 122)); border-radius:12px;left:0;bottom:0;transition:all 2s;";
143+
alertLoader.setAttribute("class", "nonny-alertLoader");
160144
this.notifyBox.appendChild(alertLoader);
161145
break;
162146
case "info":
163147
document.body.appendChild(this.notifyBox);
164-
this.notifyBox.style = `position: fixed;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;max-width:400px;background: hsl(241, 93%, 29%); color: #fff;padding: 10px; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19); ${this.placement};border: 2px solid #ddd;word-wrap:break-word;cursor:pointer;gap:1rem;`;
165-
this.notifyBox.innerHTML = `<b style="display:flex;justify-content:center;align-items:center;width:30px;height:30px; border-radius:50%;background:#fff;color:#000;font-weight:800">&#9432;</b><p style="flex:1;width:-moz-fit-content;width:fit-content; padding:0 0 6px 0; margin-right:10px; color: #f2f2f2;font-size:18px;font-weight:500;line-height:20px;cursor:pointer;"> ${msgBox}</p>`;
148+
this.notifyBox.classList.add("nm-info", this.placement);
149+
this.notifyBox.innerHTML = `<b>&#9432;</b><p>${msgBox}</p>`;
166150
alertLoader = document.createElement("span");
167-
alertLoader.setAttribute("id", "alertLoader");
168-
alertLoader.style =
169-
"position:absolute;width:100%;height:6px;background:linear-gradient(90deg,rgb(92, 66, 208),rgb(82, 75, 122)); border-radius:12px;left:0;bottom:0;transition:all 2s;";
151+
alertLoader.setAttribute("class", "nonny-alertLoader");
170152
this.notifyBox.appendChild(alertLoader);
171153
break;
172154
default:
173155
document.body.appendChild(this.notifyBox);
174-
this.notifyBox.style = `position: fixed;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;max-width:400px;background: rgb(92, 66, 208); color: #fff;padding: 10px; border-radius: 5px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19);${this.placement};border: 2px solid #ddd;word-wrap:break-word;cursor:pointer;gap:1rem`;
175-
this.notifyBox.innerHTML = `<b style="display:flex;justify-content:center;align-items:center;width:30px;height:30px; border-radius:50%;background:#fff;color:#000;font-weight:800">&#63</b><p style="flex:1;width:-moz-fit-content;width:fit-content; padding:0 0 6px 0; color: #242526;font-size:18px;font-weight:500;line-height:20px;cursor:pointer;">; ${msgBox}</p>`;
156+
this.notifyBox.classList.add("nm-default", this.placement);
157+
this.notifyBox.innerHTML = `<b>&#63;</b><p>${msgBox}</p>`;
176158
alertLoader = document.createElement("span");
177-
alertLoader.setAttribute("id", "alertLoader");
178-
alertLoader.style =
179-
"position:absolute;width:100%;height:6px;background:linear-gradient(90deg,rgb(92, 66, 208),rgb(82, 75, 122)); border-radius:12px;left:0;bottom:0;transition:all 2s;";
159+
alertLoader.setAttribute("class", "nonny-alertLoader");
180160
this.notifyBox.appendChild(alertLoader);
181161
break;
182162
}
@@ -187,9 +167,11 @@ var AlertNotify = (function () {
187167

188168
async hideOnClick() {
189169
if (document.body.contains(this.notifyBox)) {
190-
document.querySelectorAll("#alertLoader").forEach((loadIngTimeOut) => {
191-
loadIngTimeOut.style.width = "0";
192-
});
170+
document
171+
.querySelectorAll(".nonny-alertLoader")
172+
.forEach((loadIngTimeOut) => {
173+
loadIngTimeOut.style.width = "0";
174+
});
193175
await new Promise((resolve) => setTimeout(resolve, 2000));
194176
document.body.removeChild(this.notifyBox);
195177
}
@@ -202,7 +184,7 @@ var AlertNotify = (function () {
202184
clearTimeout(this.timeoutId);
203185
this.timeoutId = setTimeout(async () => {
204186
document
205-
.querySelectorAll("#alertLoader")
187+
.querySelectorAll(".nonny-alertLoader")
206188
.forEach((loadIngTimeOut) => {
207189
loadIngTimeOut.style.width = "0";
208190
});
@@ -224,27 +206,22 @@ var AlertNotify = (function () {
224206
this.autoHide(callback);
225207
}
226208

227-
triggerBox(quest, callback) {
209+
triggerBox(quest, accept, decline, callback) {
228210
const alertParentDiv = document.createElement("div");
229-
alertParentDiv.style =
230-
"position: fixed;width: 100%;height: 100%;background: rgba(0,0,0,0.212);display: flex; justify-content: center;align-items: center;top:0;left:0;right:0;padding:15px;z-index: 1000000;";
211+
alertParentDiv.setAttribute("id", "nonny-confirm-box");
231212
const alertContainerDiv = document.createElement("div");
232-
alertContainerDiv.style = `display: flex;flex-wrap:wrap;justify-content: center;align-items: center;gap: 1rem;max-width: 450px;width: 100%; background: hsl(0, 0%, 100%); box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0,0,0,0.19);border-radius: 5px;word-wrap:break-word;`;
213+
alertContainerDiv.setAttribute("id", "alertContainerDiv");
233214
const alertTextArea = document.createElement("div");
234-
alertTextArea.style =
235-
"width:100%;color: rgb(13 17 23 / 1);font-weight:500;pointer-event: auto;padding:1rem;border-bottom: 1px solid #dee2e6";
215+
alertTextArea.setAttribute("id", "alertTextArea");
236216
alertTextArea.textContent = `${quest}`;
237217
const alertBtn = document.createElement("div");
238-
alertBtn.style =
239-
"margin-top:10px;width: 100%;display: flex;justify-content: flex-end;align-items: center;gap: 1rem;padding: 10px;";
218+
alertBtn.setAttribute("class", "nonny-alertBtn");
240219
const alertOkBtn = document.createElement("button");
241-
alertOkBtn.style =
242-
"border:none;background: #23c55e; color: #242526;outline: none;padding:6px 2rem;font-size: 1rem;font-weight: 600;border-radius: 0.25rem;cursor:pointer;";
220+
alertOkBtn.classList.add("conf_ok");
243221
const alertCancelBtn = document.createElement("button");
244-
alertCancelBtn.style =
245-
"border:none;background: #eb5f51;color: #fff;outline: none;padding:6px 2rem;font-size: 1rem;font-weight: 600;border-radius: 0.25rem;cursor:pointer;";
246-
alertCancelBtn.textContent = "No!";
247-
alertOkBtn.textContent = "Yes!";
222+
alertCancelBtn.classList.add("conf_decl");
223+
alertCancelBtn.textContent = decline;
224+
alertOkBtn.textContent = accept;
248225
alertOkBtn.addEventListener("click", (e) => {
249226
e.preventDefault();
250227
callback(true);
@@ -263,19 +240,20 @@ var AlertNotify = (function () {
263240
document.body.appendChild(alertParentDiv);
264241
}
265242

266-
alert_Confirm(msg) {
243+
alert_Confirm(msg, accept = "Yes", decline = "No") {
267244
return new Promise((resolve) => {
268-
this.triggerBox(msg, (callback) => {
245+
this.triggerBox(msg, accept, decline, (callback) => {
269246
resolve(callback);
270247
});
271248
});
272249
}
273250

274251
async showModal() {
275252
await new Promise((resolve) => setTimeout(resolve, 500));
276-
document.querySelector("#nonny-modal-box").style = "margin-top:0";
277-
document.querySelector("#nonny-modal-box .modal-div").style =
278-
"margin-top:0;transform:scale(1)";
253+
document.querySelector("#nonny-modal-box").classList.add("modal-visible");
254+
document
255+
.querySelector("#nonny-modal-box .nonny-modal-div")
256+
.classList.add("scaled");
279257
}
280258

281259
async hideModal() {
@@ -284,6 +262,10 @@ var AlertNotify = (function () {
284262
if (hideThis) {
285263
hideThis.onclick = (e) => {
286264
if (e.target.classList.contains("close-nonny-modal")) {
265+
document.querySelector("#nonny-modal-box").classList.remove("modal-visible");
266+
document
267+
.querySelector("#nonny-modal-box .nonny-modal-div")
268+
.classList.remove("scaled");
287269
document.body.removeChild(hideThis);
288270
}
289271
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nonnyalertjs",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "",
55
"main": "src/nonnyalert.js",
66
"scripts": {

0 commit comments

Comments
 (0)