/* * 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 += `${address[i]}`; if (i === 0) { element.innerHTML += `-lmao`; } } }); } 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"); });