From c92001c42a56fbbb2b7d79d18bfa377ba63c22de Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Wed, 23 Mar 2022 13:05:49 -0400 Subject: Move code to standalone file and add to all loaders --- common/disable-arrow-scroll.js | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 common/disable-arrow-scroll.js (limited to 'common') diff --git a/common/disable-arrow-scroll.js b/common/disable-arrow-scroll.js new file mode 100644 index 0000000..150e9d1 --- /dev/null +++ b/common/disable-arrow-scroll.js @@ -0,0 +1,47 @@ +window.addEventListener("DOMContentLoaded", () => { + var clickedInCanvas = false; + var warning = document.createElement("div"); + warning.innerHTML = + "Arrow key scrolling disabled.
Click outside canvas or press Escape to enable again."; + warning.style.padding = "1em"; + warning.style.color = "white"; + warning.style.backgroundColor = "red"; + warning.style.position = "fixed"; + warning.style.bottom = 0; + warning.style.left = 0; + warning.style.right = 0; + warning.style.textAlign = "center"; + warning.id = "no-scroll-warning-20220323"; + warning.style.display = "none"; + warning.style.fontFamily = + "grixel_acme_7_wide_xtnd, Courier New, Verdana, Arial"; + document.body.appendChild(warning); + + function update() { + warning.style.display = clickedInCanvas ? "block" : "none"; + } + + window.addEventListener("click", (ev) => { + clickedInCanvas = ev.target.tagName.toUpperCase() == "CANVAS"; + update(); + }); + window.addEventListener( + "keydown", + (ev) => { + if (clickedInCanvas) { + if ( + ["Space", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf( + ev.code + ) > -1 + ) { + ev.preventDefault(); + } + } + if (ev.code == "Escape") { + clickedInCanvas = false; + update(); + } + }, + false + ); +}); -- cgit v1.2.3