diff --git a/gulpfile.js b/gulpfile.js index b6bc131cd..1473b92e9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -108,6 +108,7 @@ const refactoredSrc = [ "./src/js/manual-restart-tracker.js", "./src/js/config.js", "./src/js/config-set.js", + "./src/js/test/focus.js", ]; //legacy files diff --git a/src/js/commandline.js b/src/js/commandline.js index 3d60a66e4..cac05ad94 100644 --- a/src/js/commandline.js +++ b/src/js/commandline.js @@ -2159,7 +2159,7 @@ function hideCommandLine() { } let showCommandLine = () => { - setFocus(false); + Focus.set(false); $("#commandLine").removeClass("hidden"); $("#commandInput").addClass("hidden"); if ($("#commandLineWrapper").hasClass("hidden")) { diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index 4887816e8..b5e3d0dda 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -36,3 +36,4 @@ import * as CustomTextPopup from "./custom-text-popup"; import * as ManualRestart from "./manual-restart-tracker"; import Config from "./config"; import * as ConfigSet from "./config-set"; +import * as Focus from "./focus"; diff --git a/src/js/script.js b/src/js/script.js index 5e8e0b0e2..6e2168045 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -35,7 +35,6 @@ let paceCaret = null; //ui let pageTransition = false; -let focusState = false; let notSignedInLastResult = null; let verifyUserWhenLoggedIn = null; let modeBeforePractise = null; @@ -233,28 +232,6 @@ function getuid() { console.error("Only share this uid with Miodec and nobody else!"); } -function setFocus(foc) { - if (foc && !focusState) { - focusState = true; - Caret.stopAnimation(); - $("#top").addClass("focus"); - $("#bottom").addClass("focus"); - $("body").css("cursor", "none"); - $("#middle").addClass("focus"); - } else if (!foc && focusState) { - focusState = false; - if (testActive) { - Caret.stopAnimation(); - } else { - Caret.startAnimation(); - } - $("#top").removeClass("focus"); - $("#bottom").removeClass("focus"); - $("body").css("cursor", "default"); - $("#middle").removeClass("focus"); - } -} - async function initWords() { testActive = false; wordsList = []; @@ -1553,7 +1530,7 @@ function showResult(difficultyFailed = false) { resultVisible = true; TestStats.setEnd(performance.now()); testActive = false; - setFocus(false); + Focus.set(false); Caret.hide(); hideLiveWpm(); hideLiveAcc(); @@ -2750,7 +2727,7 @@ function restartTest(withSameWordset = false, nosave = false, event) { currentCorrected = ""; correctedHistory = []; ShiftTracker.reset(); - setFocus(false); + Focus.set(false); Caret.hide(); testActive = false; hideLiveWpm(); @@ -4398,7 +4375,7 @@ $(document).mousemove(function (event) { $("#top").hasClass("focus") && (event.originalEvent.movementX > 0 || event.originalEvent.movementY > 0) ) { - setFocus(false); + Focus.set(false); } }); @@ -5002,7 +4979,7 @@ function handleAlpha(event) { if (!testActive) return; } - setFocus(true); + Focus.set(true); Caret.stopAnimation(); //show dead keys diff --git a/src/js/test/focus.js b/src/js/test/focus.js new file mode 100644 index 000000000..3ec7f6896 --- /dev/null +++ b/src/js/test/focus.js @@ -0,0 +1,22 @@ +import * as Caret from "./caret"; + +let state = false; + +//TODO remove testActive once in a module +export function set(foc) { + if (foc && !state) { + state = true; + Caret.stopAnimation(); + $("#top").addClass("focus"); + $("#bottom").addClass("focus"); + $("body").css("cursor", "none"); + $("#middle").addClass("focus"); + } else if (!foc && state) { + state = false; + Caret.startAnimation(); + $("#top").removeClass("focus"); + $("#bottom").removeClass("focus"); + $("body").css("cursor", "default"); + $("#middle").removeClass("focus"); + } +}