mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-03 22:15:07 +08:00
moved out of focus to a module
This commit is contained in:
parent
8b234b0eb0
commit
8089580406
6 changed files with 32 additions and 25 deletions
|
|
@ -100,6 +100,7 @@ const refactoredSrc = [
|
|||
"./src/js/shift-tracker.js",
|
||||
"./src/js/test/test-stats.js",
|
||||
"./src/js/theme-colors.js",
|
||||
"./src/js/test/out-of-focus.js",
|
||||
];
|
||||
|
||||
//legacy files
|
||||
|
|
|
|||
|
|
@ -38,3 +38,4 @@ import * as CustomText from "./custom-text";
|
|||
import * as ShiftTracker from "./shift-tracker";
|
||||
import * as TestStats from "./test-stats";
|
||||
import * as ThemeColors from "./theme-colors";
|
||||
import * as OutOfFocus from "./out-of-focus";
|
||||
|
|
|
|||
|
|
@ -691,3 +691,10 @@ export function canQuickRestart(mode, words, time, CustomText) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearTimeouts(timeouts) {
|
||||
timeouts.forEach((to) => {
|
||||
clearTimeout(to);
|
||||
to = null;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1793,7 +1793,7 @@ function showResult(difficultyFailed = false) {
|
|||
}
|
||||
$("#result .stats .key .bottom").text(testtime + "s");
|
||||
$("#words").removeClass("blurred");
|
||||
$(".outOfFocusWarning").addClass("hidden");
|
||||
OutOfFocus.hide();
|
||||
$("#result .stats .key .bottom").text(
|
||||
stats.correctChars +
|
||||
stats.correctSpaces +
|
||||
|
|
@ -4635,32 +4635,16 @@ $("#wordsInput").keypress((event) => {
|
|||
event.preventDefault();
|
||||
});
|
||||
|
||||
let outOfFocusTimeouts = [];
|
||||
|
||||
function clearTimeouts(timeouts) {
|
||||
timeouts.forEach((to) => {
|
||||
clearTimeout(to);
|
||||
to = null;
|
||||
});
|
||||
}
|
||||
|
||||
$("#wordsInput").on("focus", () => {
|
||||
if (!resultVisible && config.showOutOfFocusWarning) {
|
||||
$("#words").css("transition", "none").removeClass("blurred");
|
||||
$(".outOfFocusWarning").addClass("hidden");
|
||||
clearTimeouts(outOfFocusTimeouts);
|
||||
OutOfFocus.hide();
|
||||
}
|
||||
showCaret();
|
||||
});
|
||||
|
||||
$("#wordsInput").on("focusout", () => {
|
||||
if (!resultVisible && config.showOutOfFocusWarning) {
|
||||
outOfFocusTimeouts.push(
|
||||
setTimeout(() => {
|
||||
$("#words").css("transition", "0.25s").addClass("blurred");
|
||||
$(".outOfFocusWarning").removeClass("hidden");
|
||||
}, 1000)
|
||||
);
|
||||
OutOfFocus.show();
|
||||
}
|
||||
hideCaret();
|
||||
});
|
||||
|
|
|
|||
18
src/js/test/out-of-focus.js
Normal file
18
src/js/test/out-of-focus.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import * as Misc from "./misc";
|
||||
|
||||
let outOfFocusTimeouts = [];
|
||||
|
||||
export function hide() {
|
||||
$("#words").css("transition", "none").removeClass("blurred");
|
||||
$(".outOfFocusWarning").addClass("hidden");
|
||||
Misc.clearTimeouts(outOfFocusTimeouts);
|
||||
}
|
||||
|
||||
export function show() {
|
||||
outOfFocusTimeouts.push(
|
||||
setTimeout(() => {
|
||||
$("#words").css("transition", "0.25s").addClass("blurred");
|
||||
$(".outOfFocusWarning").removeClass("hidden");
|
||||
}, 1000)
|
||||
);
|
||||
}
|
||||
|
|
@ -358,9 +358,7 @@ function setAlwaysShowCPM(val, nosave) {
|
|||
function toggleShowOutOfFocusWarning() {
|
||||
config.showOutOfFocusWarning = !config.showOutOfFocusWarning;
|
||||
if (!config.showOutOfFocusWarning) {
|
||||
$("#words").css("transition", "none").removeClass("blurred");
|
||||
$(".outOfFocusWarning").addClass("hidden");
|
||||
clearTimeouts(outOfFocusTimeouts);
|
||||
OutOfFocus.hide();
|
||||
}
|
||||
saveConfigToCookie();
|
||||
}
|
||||
|
|
@ -371,9 +369,7 @@ function setShowOutOfFocusWarning(val, nosave) {
|
|||
}
|
||||
config.showOutOfFocusWarning = val;
|
||||
if (!config.showOutOfFocusWarning) {
|
||||
$("#words").css("transition", "none").removeClass("blurred");
|
||||
$(".outOfFocusWarning").addClass("hidden");
|
||||
clearTimeouts(outOfFocusTimeouts);
|
||||
OutOfFocus.hide();
|
||||
}
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue