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
|
/*
* Functions
*/
function sleep(ms) {
/**
* Sleep in milliseconds
*/
return new Promise((resolve) => setTimeout(resolve, ms));
}
function fillMail(address, fillElement) {
/**
* Puts the email address in the element
*/
document.querySelectorAll(`${fillElement}`).forEach((element) => {
element.textContent = "";
for (let i = 0; i < address.length; i++) {
element.innerHTML += `<span>${address[i]}</span>`;
if (i === 0) {
element.innerHTML += `<span class="d-none">-lmao<hr hidden /><br hidden /></span>`;
}
}
});
}
let canStartCopyAnimation = true;
function copyText(element, event) {
/**
* Copies text to clipboard and starts a popup animation
*/
navigator.clipboard.writeText(element.textContent.replaceAll("-lmao", "")).then(
async () => {
if (canStartCopyAnimation === false) return;
canStartCopyAnimation = false;
document.querySelector("#clipboard").hidden = false;
await sleep(50)
document.querySelector("#clipboard").style.opacity = "100";
document.querySelector("#clipboard").style.visibility= "visible";
await sleep(3000);
document.querySelector("#clipboard").style.opacity = "0"
canStartCopyAnimation = true;
await sleep(1000);
if (canStartCopyAnimation === false) return;
document.querySelector("#clipboard").style.visibility = "hidden";
}
);
}
/*
* Main logic
*/
document.querySelectorAll(".onclick-copy").forEach((element) => {
element.classList.add("a");
})
fillMail(
[
// {{- range .Site.Params.mailPersonal }}
"{{ . }}",
// {{- end }}
],
".mail--personal"
);
document.querySelectorAll(".onclick-copy").forEach((element) => {
element.addEventListener("click", (event) => {
copyText(element, event);
});
element.addEventListener("keydown", (event) => {
if (event.key === "Enter") copyText(element, event);
});
});
/*
* Accessibility
*/
let navLinks = document.querySelector("#navbar__menu");
let hamburger = document.querySelector("#hamburger")
if (hamburger.checked === false)
navLinks.setAttribute("aria-expanded", "false");
else navLinks.setAttribute("aria-expanded", "true");
hamburger.addEventListener("click", (e) => {
if (navLinks.getAttribute("aria-expanded") === "false")
navLinks.setAttribute("aria-expanded", "true")
else navLinks.setAttribute("aria-expanded", "false");
});
|