Skip to content

Commit b0ced8b

Browse files
committed
updated Toast class
1 parent ad2bba5 commit b0ced8b

File tree

8 files changed

+88
-157
lines changed

8 files changed

+88
-157
lines changed

dev/js/hexer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ hexer.prototype.init_u_area = function() {
2020

2121
this.inputfield.addEventListener('change', (e)=>{
2222
if (e.target.files.length > 1) {
23-
t.newToast('Only one file is allowed');
23+
2424
}
2525
this.fileHandler(e.target.files[0]);
2626
});
@@ -44,7 +44,7 @@ hexer.prototype.init_u_area = function() {
4444
e.preventDefault();
4545

4646
if (e.dataTransfer.files.length > 1) {
47-
t.newToast('Only one file is allowed');
47+
Toast('Only one file is allowed');
4848
}
4949

5050
this.fileHandler(e.dataTransfer.files[0]);
@@ -66,12 +66,12 @@ hexer.prototype.readFile = function() {
6666

6767
fr.onloadstart = (e)=>{
6868
document.getElementById('up-status').className = 'soft-blink';
69-
t.newToast('Reading file.', toastt.SHORT);
69+
Toast('Reading file.', Toast.SHORT);
7070
};
7171

7272
fr.onloadend = (e)=>{
7373
document.getElementById('up-status').className = 'done';
74-
t.newToast('File has been read.', toastt.SHORT);
74+
Toast('File has been read.', Toast.SHORT);
7575
this.buffer = new Uint8Array(e.target.result);
7676
this.createHexPage();
7777
};
@@ -514,7 +514,7 @@ hexer.prototype.saveFile = function() {
514514
document.getElementById('download-file').click();
515515

516516
} else {
517-
t.newToast('You have to load a file in order to save it.', toastt.SHORT);
517+
Toast('You have to load a file in order to save it.', Toast.SHORT);
518518
}
519519

520520
});

dev/js/page.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pages.prototype.loadPreviousPage = function(sp) {
5555
let p = document.querySelector(`[data-page-id="${sp}"]`);
5656
if (p == undefined) {
5757
console.error("Back: Page does not exist!");
58-
t.newToast("Back: Page does not exist!", toastt.SHORT);
58+
Toast('Back: Page does not exist!', Toast.SHORT);
5959
} else {
6060
this.currentPage = sp;
6161

@@ -72,7 +72,7 @@ pages.prototype.loadPageById = function(sp) {
7272
let p = document.querySelector(`[data-page-id="${sp}"]`);
7373
if (p == undefined) {
7474
console.error("Page does not exist!");
75-
t.newToast("Page does not exist!", toastt.SHORT);
75+
Toast('Page does not exist!', Toast.SHORT);
7676
} else {
7777
this.previousPage.push(this.currentPage);
7878
this.currentPage = sp;

dev/js/toast.js

+12-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
1-
var toastt = {
2-
LONG: 6000,
3-
SHORT: 3200
4-
};
1+
function Toast(text, time=Toast.SHORT) {
52

6-
function toast() {
3+
const cont = document.getElementById('toast-container');
4+
const chil = document.createElement('div');
5+
chil.className = 'toast';
6+
chil.innerHTML = `<p>${text}</p>`;
77

8-
this.toast = document.getElementById('toast');
9-
this.next = [];
10-
this.active = false;
11-
}
12-
13-
toast.prototype.newToast = function(text, length) {
14-
15-
if (!this.active) {
16-
this.active = true;
8+
cont.appendChild(chil);
179

18-
document.getElementById('toast-text').innerHTML = text;
19-
this.toast.className = 'show';
10+
setTimeout(()=>{
11+
chil.remove();
12+
}, time);
2013

21-
this.timer = setTimeout( ()=>{
22-
this.toast.className += ' hide';
23-
setTimeout( ()=>{
24-
this.toast.className = '';
25-
this.toastText = '';
26-
this.active = false;
27-
}, 250 );
28-
29-
}, length);
30-
31-
} else {
32-
document.getElementById('toast-text').innerHTML += '<br>' + text;
33-
}
14+
}
3415

35-
};
16+
Toast.LONG = 6000;
17+
Toast.SHORT = 3200;

dev/js/zinit.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ window.addEventListener('click', (e)=>{
1919
c = new config();
2020
s = new settings();
2121
p = new pages();
22-
t = new toast();
2322
h = new hexer();
2423

2524
}();

dev/sass/modules/_toast.sass

+25-41
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,27 @@
1-
.toast-positioner
2-
display: flex;
3-
justify-content: center;
4-
5-
#toast
1+
.toast-position
62
position: fixed;
7-
bottom: -100%;
8-
min-height: 60px;
9-
color: $col-inv;
10-
background-color: $col-font;
11-
margin: 0 12px 12px 12px;
12-
border-radius: 4px;
13-
max-width: 730px;
14-
display: flex;
15-
justify-content: center;
16-
align-items: center;
17-
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
18-
19-
p
20-
margin: 0;
21-
padding: 12px 24px;
22-
font-size: 1.2em;
23-
24-
25-
.show
26-
animation: -show-toast 200ms forwards;
3+
bottom: 0;
4+
width: 100%;
275

28-
@keyframes -show-toast
29-
0%
30-
bottom: -100%;
31-
32-
100%
33-
bottom: 0;
34-
35-
.hide
36-
animation: -hide-toast 200ms forwards;
37-
38-
@keyframes -hide-toast
39-
0%
40-
bottom: 0;
41-
42-
100%
43-
bottom: -100%;
6+
#toast-container
7+
display: flex;
8+
flex-direction: column;
9+
transition: all 200ms ease-out;
10+
11+
.toast
12+
margin: auto;
13+
width: 100%;
14+
15+
@media #{$mq-desktop}
16+
width: 420px;
17+
18+
background-color: $col-font;
19+
margin-bottom: 12px;
20+
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
21+
border-radius: 2px;
22+
23+
p
24+
padding: 21px 36px;
25+
margin: 0;
26+
color: $col-inv;
27+
font-size: 1.2em;

public/css/main.css

+22-37
Original file line numberDiff line numberDiff line change
@@ -199,45 +199,30 @@ a {
199199
opacity: 1 !important;
200200
background-color: #4CAF50 !important; }
201201

202-
.toast-positioner {
203-
display: flex;
204-
justify-content: center; }
205-
206-
#toast {
202+
.toast-position {
207203
position: fixed;
208-
bottom: -100%;
209-
min-height: 60px;
210-
color: #fefefe;
211-
background-color: #333333;
212-
margin: 0 12px 12px 12px;
213-
border-radius: 4px;
214-
max-width: 730px;
215-
display: flex;
216-
justify-content: center;
217-
align-items: center;
218-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); }
219-
#toast p {
220-
margin: 0;
221-
padding: 12px 24px;
222-
font-size: 1.2em; }
223-
224-
.show {
225-
animation: -show-toast 200ms forwards; }
226-
227-
@keyframes -show-toast {
228-
0% {
229-
bottom: -100%; }
230-
100% {
231-
bottom: 0; } }
232-
233-
.hide {
234-
animation: -hide-toast 200ms forwards; }
204+
bottom: 0;
205+
width: 100%; }
235206

236-
@keyframes -hide-toast {
237-
0% {
238-
bottom: 0; }
239-
100% {
240-
bottom: -100%; } }
207+
#toast-container {
208+
display: flex;
209+
flex-direction: column;
210+
transition: all 200ms ease-out; }
211+
#toast-container .toast {
212+
margin: auto;
213+
width: 100%;
214+
background-color: #333333;
215+
margin-bottom: 12px;
216+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
217+
border-radius: 2px; }
218+
@media (min-width: 1200px) {
219+
#toast-container .toast {
220+
width: 420px; } }
221+
#toast-container .toast p {
222+
padding: 21px 36px;
223+
margin: 0;
224+
color: #fefefe;
225+
font-size: 1.2em; }
241226

242227
#hex-view {
243228
padding: 12px 0; }

public/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ <h2>Configuration</h2>
232232
&copy; Andy Bitz 2017
233233
</div>
234234

235-
<div class="toast-positioner">
236-
<div id="toast">
237-
<p id="toast-text"></p>
235+
<div class="toast-position">
236+
<div id="toast-container">
237+
238238
</div>
239239
</div>
240240

public/js/script.js

+19-38
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ hexer.prototype.init_u_area = function() {
506506

507507
this.inputfield.addEventListener('change', (e)=>{
508508
if (e.target.files.length > 1) {
509-
t.newToast('Only one file is allowed');
509+
510510
}
511511
this.fileHandler(e.target.files[0]);
512512
});
@@ -530,7 +530,7 @@ hexer.prototype.init_u_area = function() {
530530
e.preventDefault();
531531

532532
if (e.dataTransfer.files.length > 1) {
533-
t.newToast('Only one file is allowed');
533+
Toast('Only one file is allowed');
534534
}
535535

536536
this.fileHandler(e.dataTransfer.files[0]);
@@ -552,12 +552,12 @@ hexer.prototype.readFile = function() {
552552

553553
fr.onloadstart = (e)=>{
554554
document.getElementById('up-status').className = 'soft-blink';
555-
t.newToast('Reading file.', toastt.SHORT);
555+
Toast('Reading file.', Toast.SHORT);
556556
};
557557

558558
fr.onloadend = (e)=>{
559559
document.getElementById('up-status').className = 'done';
560-
t.newToast('File has been read.', toastt.SHORT);
560+
Toast('File has been read.', Toast.SHORT);
561561
this.buffer = new Uint8Array(e.target.result);
562562
this.createHexPage();
563563
};
@@ -1000,7 +1000,7 @@ hexer.prototype.saveFile = function() {
10001000
document.getElementById('download-file').click();
10011001

10021002
} else {
1003-
t.newToast('You have to load a file in order to save it.', toastt.SHORT);
1003+
Toast('You have to load a file in order to save it.', Toast.SHORT);
10041004
}
10051005

10061006
});
@@ -1063,7 +1063,7 @@ pages.prototype.loadPreviousPage = function(sp) {
10631063
let p = document.querySelector(`[data-page-id="${sp}"]`);
10641064
if (p == undefined) {
10651065
console.error("Back: Page does not exist!");
1066-
t.newToast("Back: Page does not exist!", toastt.SHORT);
1066+
Toast('Back: Page does not exist!', Toast.SHORT);
10671067
} else {
10681068
this.currentPage = sp;
10691069

@@ -1080,7 +1080,7 @@ pages.prototype.loadPageById = function(sp) {
10801080
let p = document.querySelector(`[data-page-id="${sp}"]`);
10811081
if (p == undefined) {
10821082
console.error("Page does not exist!");
1083-
t.newToast("Page does not exist!", toastt.SHORT);
1083+
Toast('Page does not exist!', Toast.SHORT);
10841084
} else {
10851085
this.previousPage.push(this.currentPage);
10861086
this.currentPage = sp;
@@ -1157,41 +1157,23 @@ settings.prototype.toggle = function() {
11571157

11581158
};
11591159

1160-
var toastt = {
1161-
LONG: 6000,
1162-
SHORT: 3200
1163-
};
1164-
1165-
function toast() {
1166-
1167-
this.toast = document.getElementById('toast');
1168-
this.next = [];
1169-
this.active = false;
1170-
}
1171-
1172-
toast.prototype.newToast = function(text, length) {
1160+
function Toast(text, time=Toast.SHORT) {
11731161

1174-
if (!this.active) {
1175-
this.active = true;
1162+
const cont = document.getElementById('toast-container');
1163+
const chil = document.createElement('div');
1164+
chil.className = 'toast';
1165+
chil.innerHTML = `<p>${text}</p>`;
11761166

1177-
document.getElementById('toast-text').innerHTML = text;
1178-
this.toast.className = 'show';
1167+
cont.appendChild(chil);
11791168

1180-
this.timer = setTimeout( ()=>{
1181-
this.toast.className += ' hide';
1182-
setTimeout( ()=>{
1183-
this.toast.className = '';
1184-
this.toastText = '';
1185-
this.active = false;
1186-
}, 250 );
1169+
setTimeout(()=>{
1170+
chil.remove();
1171+
}, time);
11871172

1188-
}, length);
1189-
1190-
} else {
1191-
document.getElementById('toast-text').innerHTML += '<br>' + text;
1192-
}
1173+
}
11931174

1194-
};
1175+
Toast.LONG = 6000;
1176+
Toast.SHORT = 3200;
11951177
var g, h, t, p, s, c;
11961178

11971179
var mq = {
@@ -1213,7 +1195,6 @@ window.addEventListener('click', (e)=>{
12131195
c = new config();
12141196
s = new settings();
12151197
p = new pages();
1216-
t = new toast();
12171198
h = new hexer();
12181199

12191200
}();

0 commit comments

Comments
 (0)