-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbert.js
executable file
·107 lines (93 loc) · 2.46 KB
/
bert.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
class BertAlert {
constructor() {
this.styles = [
'fixed-top',
'fixed-bottom',
'growl-top-left',
'growl-top-right',
'growl-bottom-left',
'growl-bottom-right'
];
this.types = [
'default',
'success',
'info',
'warning',
'danger'
];
this.icons = {
default: 'fas fa-bell',
success: 'fas fa-check',
info: 'fas fa-info',
warning: 'fas fa-exclamation-triangle',
danger: 'fas fa-times'
};
this.defaults = {
hideDelay: 3500,
style: 'fixed-top',
type: 'default'
};
}
alert() {
if ( this.isVisible() ) {
this.hide();
setTimeout( () => { this.handleAlert( arguments ); }, 300 );
} else {
this.handleAlert( arguments );
}
}
isVisible() {
return $( '.bert-alert' ).hasClass( 'show' );
}
handleAlert( alert ) {
this.registerClickHandler();
this.setBertOnSession( alert );
requestAnimationFrame(() => this.show());
this.bertTimer();
}
registerClickHandler() {
$( '.bert-alert' ).off( 'click' );
$( '.bert-alert' ).on( 'click', () => { this.hide(); } );
}
bertTimer() {
clearTimeout( this.timer );
this.timer = setTimeout( () => { this.hide(); }, this.defaults.hideDelay );
return this.timer;
}
show() {
$( '.bert-alert' ).addClass( 'show' ).delay( 25 ).queue( () => {
$( '.bert-alert' ).addClass( 'animate' ).dequeue();
});
}
hide() {
$( '.bert-alert' ).removeClass( 'animate' );
setTimeout( () => {
$( '.bert-alert' ).removeClass( 'show' );
$( '.bert-icon').remove();
Session.set( 'bertAlert', null );
}, 300 );
}
setBertOnSession( alert ) {
if ( typeof alert[0] === 'object' ) {
let type = alert[0].type || this.defaults.type;
const icon = alert[0].icon || this.icons[ type ];
Session.set( 'bertAlert', {
title: alert[0].title || "",
message: alert[0].message || "",
type: type,
style: alert[0].style || this.defaults.style,
icon: `<div class="bert-icon"><i class="${icon}"></i></div>`
});
} else {
let type = alert[1] || this.defaults.type;
const icon = alert[3] || this.icons[ type ];
Session.set( 'bertAlert', {
message: alert[0] || "",
type: type,
style: alert[2] || this.defaults.style,
icon: `<div class="bert-icon"><i class="${icon}"></i></div>`
});
}
}
}
Bert = new BertAlert();