From 3b57e308356d889a5f3f5b2565ebe8e672f995fe Mon Sep 17 00:00:00 2001 From: Luke Harold Miles <10591373+qpwo@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:23:32 -0800 Subject: [PATCH 1/2] fix `controlled` stuck on open new tab --- _web/_includes/go-js.html | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/_web/_includes/go-js.html b/_web/_includes/go-js.html index 773eb91..806d757 100644 --- a/_web/_includes/go-js.html +++ b/_web/_includes/go-js.html @@ -1111,6 +1111,8 @@ if (!$("#hero").is(":visible") || $("#controls").is(":visible") || jukeboxData.disableKeys) { return; } + controlled = e.ctrlKey + shifted = e.shiftKey if (evt.which === 39) { // right arrow var inc = driver.getIncr(); @@ -1144,10 +1146,6 @@ } - if (evt.which === 17) { // control - controlled = true; - } - if (evt.which === 72) { // h jukeboxData.infiniteMode = !jukeboxData.infiniteMode; if (jukeboxData.infiniteMode) { @@ -1157,10 +1155,6 @@ } } - if (evt.which === 16) { // shift - shifted = true; - } - if (evt.which === 32) { // space evt.preventDefault(); if (driver.isRunning()) { @@ -1173,12 +1167,13 @@ } function keyup(evt) { - if (evt.which == 17) { // control - controlled = false; - } - if (evt.which == 16) { // shift - shifted = false; - } + controlled = e.ctrlKey + shifted = e.shiftKey + } + + function keypress() { + controlled = e.ctrlKey + shifted = e.shiftKey } function getShareURL(callback) { @@ -1208,6 +1203,7 @@ $(document).keydown(keydown); $(document).keyup(keyup); + $(document).keypress(keypress); paper = Raphael("tiles", W, H); From 6429fa3353a6cacdec49dcdb915f4cb485e327a1 Mon Sep 17 00:00:00 2001 From: Luke Harold Miles <10591373+qpwo@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:34:31 -0800 Subject: [PATCH 2/2] more reliable --- _web/_includes/go-js.html | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/_web/_includes/go-js.html b/_web/_includes/go-js.html index 806d757..7c57ef0 100644 --- a/_web/_includes/go-js.html +++ b/_web/_includes/go-js.html @@ -1111,8 +1111,6 @@ if (!$("#hero").is(":visible") || $("#controls").is(":visible") || jukeboxData.disableKeys) { return; } - controlled = e.ctrlKey - shifted = e.shiftKey if (evt.which === 39) { // right arrow var inc = driver.getIncr(); @@ -1166,14 +1164,14 @@ } - function keyup(evt) { - controlled = e.ctrlKey - shifted = e.shiftKey + function updateCtrlShift(evt) { + controlled = evt.ctrlKey + shifted = evt.shiftKey } - function keypress() { - controlled = e.ctrlKey - shifted = e.shiftKey + function resetCtrlShit() { + controlled = false; + shifted = false; } function getShareURL(callback) { @@ -1202,8 +1200,12 @@ }; $(document).keydown(keydown); - $(document).keyup(keyup); - $(document).keypress(keypress); + + window.addEventListener('keydown', updateCtrlShift) + window.addEventListener('keyup', updateCtrlShift) + window.addEventListener('keypress', updateCtrlShift) + document.addEventListener('blur', resetCtrlShit); + window.addEventListener('blur', resetCtrlShit); paper = Raphael("tiles", W, H);