-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashs.js
42 lines (35 loc) · 1.46 KB
/
flashs.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
/*
##### flashes messages #####
# Developed by Baramex #
### github: https://github.com/baramex ###
License: lgpl-3.0
*/
window.addEventListener("load", () => {
var div = document.createElement("div");
div.id = "flashDiv",
div.style = "z-index: 6;top: 0;left: 0;width: 80%;margin-left: 10%;position: fixed;";
document.body.appendChild(div);
});
function appendFlash(type, message, time = 2500, parent = null) {
var flash = generateFlash(type, message);
if (parent) {
parent.appendChild(flash);
} else {
if (document.getElementById("flashDiv")) document.getElementById("flashDiv").appendChild(flash);
else console.error("Please wait body is loaded to generate flash!");
}
if (time != 0) {
setTimeout(function() {
$(flash).fadeOut(500, function() {
flash.remove();
});
}, time);
}
}
function generateFlash(type, message) {
var flash = document.createElement("div");
flash.classList.add("flash");
flash.classList.add(type);
flash.innerHTML = "<p style='display: inline-block;vertical-align: middle;margin: 0;margin-left: 3px;'><img style='vertical-align: middle;' src='http://cdn.baramex.fr/utils/images/flashs/" + type + ".png' width='50px'></p> <p class='mes' style='display: inline-block; padding: 5px;line-height: 40px; margin: 0'>" + message + "</p>";
return flash;
}