-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2.toasts.js
More file actions
80 lines (77 loc) · 1.69 KB
/
2.toasts.js
File metadata and controls
80 lines (77 loc) · 1.69 KB
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
fn.toast = (arg) => {
// Why do I even check for SimpleToast? It *has* to be loaded at this point...
if (!window.SimpleToast || !arg) return false;
if (typeof arg === 'string') {
arg = {
text: arg,
};
}
const defaults = {
footer: 'via UnderScript',
css: {
'background-color': 'rgba(0,5,20,0.6)',
'text-shadow': '',
'font-family': 'monospace',
footer: {
'text-align': 'end',
},
},
};
return new SimpleToast(fn.merge(defaults, arg));
};
fn.errorToast = (error) => {
const toast = {
title: error.name || 'Error',
text: error.message || error,
css: {
'background-color': 'rgba(200,0,0,0.6)',
}
};
return fn.toast(toast);
};
fn.infoToast = (arg, key, val) => {
if (localStorage.getItem(key) === val) return null;
if (typeof arg === 'string') {
arg = {
text: arg,
};
} else if (typeof arg !== 'object') return null;
const override = {
onClose: (...args) => {
if (typeof arg.onClose === 'function') {
if (arg.onClose(...args)) {
return;
}
}
localStorage.setItem(key, val);
},
};
const defaults = {
title: 'Did you know?',
css: {
'font-family': 'inherit',
},
};
return fn.toast(fn.merge(defaults, arg, override));
};
fn.dismissable = ({title, text, key}) => {
const buttons = {
text: 'Dismiss',
className: 'dismiss',
css: {
border: '',
height: '',
background: '',
'font-size': '',
'margin': '',
'border-radius': '',
},
onclick: (e) => {
localStorage.setItem(key, true);
},
};
return fn.toast({
title, text, buttons,
className: 'dismissable',
});
};