mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 05:17:51 +08:00
added focus module. part of #495
This commit is contained in:
parent
f1d6f4a3e5
commit
e9dd9bedb9
5 changed files with 29 additions and 28 deletions
|
@ -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
|
||||
|
|
|
@ -2159,7 +2159,7 @@ function hideCommandLine() {
|
|||
}
|
||||
|
||||
let showCommandLine = () => {
|
||||
setFocus(false);
|
||||
Focus.set(false);
|
||||
$("#commandLine").removeClass("hidden");
|
||||
$("#commandInput").addClass("hidden");
|
||||
if ($("#commandLineWrapper").hasClass("hidden")) {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
22
src/js/test/focus.js
Normal file
22
src/js/test/focus.js
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue