Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Baramex committed Aug 27, 2021
1 parent db3ee93 commit 6530cfd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion exemple.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script src="http://baramex.fr:9999/cdn/flashes-messages/flashs.js"></script>
</head>

<body onload='createFlash("success-flash", "success flash!", 2000);createFlash("info-flash", "info flash!", 3000);createFlash("not-allowed-flash", "not allowed flash!", 4000);createFlash("error-flash", "error flash!", 5000);' style="font-family: sans-serif;">
<body onload='appendFlash("success-flash", "success flash!", 2000);appendFlash("info-flash", "info flash!", 3000);appendFlash("not-allowed-flash", "not allowed flash!", 4000);appendFlash("error-flash", "error flash!", 5000);' style="font-family: sans-serif;">

</body>

Expand Down
34 changes: 23 additions & 11 deletions flashs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,34 @@ Licence: 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;";
div.style = "z-index: 6;top: 0;left: 0;width: 80%;margin-left: 10%;position: fixed;";
document.body.appendChild(div);
});

function createFlash(type, message, time=2500) {
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://baramex.fr:9999/utils/images/flashs/" + type + ".png' width='50px'></p> <p class='mes' style='display: inline-block; padding: 5px;line-height: 40px; margin: 0'>" + message + "</p>";
if(document.getElementById("flashDiv")) document.getElementById("flashDiv").appendChild(flash);
else console.error("Please wait body is loaded to generate flash!");

if(time != 0)
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)
}, 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://baramex.fr:9999/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;
}

0 comments on commit 6530cfd

Please sign in to comment.