-
Notifications
You must be signed in to change notification settings - Fork 9
/
faint.js
74 lines (61 loc) · 1.72 KB
/
faint.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
(function faintFactory() {
'use strict';
const clsPrefix = 'faint';
const styles = `
.${clsPrefix} {
z-index: 1000;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
visibility: hidden;
opacity: 0;
transition: 1s linear;
transition-property: opacity, visibility;
}
.${clsPrefix}.open {
visibility: visible;
opacity: 1;
transition: 1s linear;
transition-property: opacity, visibility;
}
html.${clsPrefix}-blur {
filter: blur(10px);
transition: 1s filter linear;
/* without these 2 lines, firefox does weird things */
height: 100%;
overflow: hidden;
}
`;
jQuery(`<style type="text/css" id="${clsPrefix}-style">${styles}</style>`).appendTo('head');
const body = jQuery('body');
const doc = jQuery('html');
const overlay = jQuery(`<div class="${clsPrefix}"></div>`);
overlay.appendTo(body);
function comeTo() {
overlay.removeClass('open');
doc.removeClass(`${clsPrefix}-blur`);
}
function faint(callback = null, duration = 5, color = 'black', blur = true) {
overlay.css({backgroundColor: color});
if (blur) {
doc.addClass(`${clsPrefix}-blur`);
}
overlay.addClass('open');
setTimeout(() => {
if (callback) {
callback();
setTimeout(comeTo, 100); // make a small delay to let callback finish
} else {
comeTo();
}
}, duration * 1000);
}
window.scUtils = Object.assign(
window.scUtils || {},
{
faint,
}
);
}());