fix touch events on mobile

trunk
vilmibm 2023-08-04 00:59:21 +00:00
parent f9082d4d3e
commit 0f341fa482
1 changed files with 36 additions and 11 deletions

View File

@ -3,6 +3,7 @@
<head> <head>
<title>blackout engine</title> <title>blackout engine</title>
<script src="/html2canvas.min.js"></script> <script src="/html2canvas.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.3" />
</head> </head>
<body> <body>
<style> <style>
@ -37,6 +38,10 @@
background-color: black; background-color: black;
} }
.grey {
background-color: grey;
}
.hidden { .hidden {
display: none; display: none;
} }
@ -61,12 +66,14 @@
cursor: help; cursor: help;
} }
#paper span:hover { @media (hover: hover) {
background-color: white; #paper span:hover {
} background-color: white;
}
#paper span.black:hover { #paper span.black:hover {
background-color: grey; background-color: grey;
}
} }
#aboutToggle { #aboutToggle {
@ -130,15 +137,32 @@
</div> </div>
</center> </center>
<script> <script>
document.querySelectorAll("#paper span").forEach(span => document.querySelectorAll("#paper span").forEach(span => {
span.onclick = () => span.classList.toggle("black")); span.addEventListener("click", () => span.classList.toggle("black"));
span.addEventListener("touchstart", (e) => {
e.preventDefault();
span.classList.add("grey");
});
span.addEventListener("touchend", (e) => {
e.preventDefault();
span.classList.remove("grey");
span.classList.toggle("black");
});
span.addEventListener("touchcancel", (e) => {
e.preventDefault();
span.classList.remove("grey");
});
});
document.querySelector("#aboutToggle").onclick = (e) => { document.querySelector("#aboutToggle").onclick = (e) => {
e.preventDefault(); e.preventDefault();
document.querySelector("#about").classList.toggle("hidden"); document.querySelector("#about").classList.toggle("hidden");
} }
const copyImgButton = document.querySelector("#copyImage"); const copyImgButton = document.querySelector("#copyImage");
copyImgButton.addEventListener("animationend", () => copyImgButton.classList.remove("rainbow"), false); copyImgButton.addEventListener("animationend", () => copyImgButton.classList.remove("rainbow"), false);
copyImgButton.onclick = () => { copyImgButton.addEventListener("click", () => {
html2canvas(document.querySelector("#paper")).then((canvas) => { html2canvas(document.querySelector("#paper")).then((canvas) => {
canvas.toBlob((blob) => { canvas.toBlob((blob) => {
let data = [new ClipboardItem({ [blob.type]: blob })]; let data = [new ClipboardItem({ [blob.type]: blob })];
@ -147,10 +171,11 @@
}, console.log); }, console.log);
}); });
}); });
} });
const copyTextButton = document.querySelector("#copyText"); const copyTextButton = document.querySelector("#copyText");
copyTextButton.addEventListener("animationend", () => copyTextButton.classList.remove("rainbow"), false); copyTextButton.addEventListener("animationend", () => copyTextButton.classList.remove("rainbow"), false);
copyTextButton.onclick = () => { copyTextButton.addEventListener("click", () => {
let toCopy = ""; let toCopy = "";
document.querySelectorAll("#paper span").forEach(span => { document.querySelectorAll("#paper span").forEach(span => {
let guts = span.innerHTML; let guts = span.innerHTML;
@ -187,7 +212,7 @@
}, (err) => { }, (err) => {
console.log(err); console.log(err);
}); });
} });
</script> </script>
</body> </body>
</html> </html>