-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
23 lines (22 loc) · 810 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function copyTextToClipboard (text) {
let input = document.getElementById("input-copy-to-clipboard");
input.value = text;
input.select();
input.setSelectionRange(0, text.length);
document.execCommand("copy");
input.blur();
showToast("Copied to Clipboard!");
}
export function showToast (text, durationInSeconds=2) {
let boxToasts = document.getElementById("div-toasts");
let toast = boxToasts.getElementsByTagName("template")[0].content.children[0].cloneNode(true);
toast.innerText = text; // TODO!
boxToasts.appendChild(toast);
toast.style.opacity = 1;
setTimeout(function () {
toast.style.opacity = 0; // fade out
setTimeout(function () {
boxToasts.removeChild(toast);
}, 3000);
}, durationInSeconds*1000);
}