added test config module #495

This commit is contained in:
Miodec 2021-03-28 02:00:23 +01:00
parent 280481b262
commit 716121eb45
4 changed files with 82 additions and 77 deletions

View file

@ -132,6 +132,7 @@ const refactoredSrc = [
"./src/js/commandline.js",
"./src/js/challenge-controller.js",
"./src/js/custom-mode2-popup.js",
"./src/js/test/test-config.js",
];
//legacy files

View file

@ -55,3 +55,4 @@ import * as Commandline from "./commandline";
import * as CommandlineLists from "./commandline-lists";
import * as ChallengeController from "./challenge-controller";
import * as CustomMode2Popup from "./custom-mode2-popup";
import * as TestConfig from "./test-config";

View file

@ -132,14 +132,6 @@ function highlightBadWord(index, showError) {
$($("#words .word")[index]).addClass("error");
}
function showTestConfig() {
$("#top .config").removeClass("hidden").css("opacity", 1);
}
function hideTestConfig() {
$("#top .config").css("opacity", 0).addClass("hidden");
}
function startTest() {
if (UI.pageTransition) {
return false;
@ -195,7 +187,7 @@ function changePage(page) {
$(".page.pageTest").addClass("active");
history.pushState("/", null, "/");
});
showTestConfig();
TestConfig.show();
hideSignOutButton();
// restartCount = 0;
// incompleteTestSeconds = 0;
@ -210,7 +202,7 @@ function changePage(page) {
history.pushState("about", null, "about");
$(".page.pageAbout").addClass("active");
});
hideTestConfig();
TestConfig.hide();
hideSignOutButton();
} else if (page == "settings") {
UI.setPageTransition(true);
@ -221,7 +213,7 @@ function changePage(page) {
$(".page.pageSettings").addClass("active");
});
updateSettingsPage();
hideTestConfig();
TestConfig.hide();
hideSignOutButton();
} else if (page == "account") {
if (!firebase.auth().currentUser) {
@ -235,7 +227,7 @@ function changePage(page) {
$(".page.pageAccount").addClass("active");
});
refreshAccountPage();
hideTestConfig();
TestConfig.hide();
showSignOutButton();
}
} else if (page == "login") {
@ -249,7 +241,7 @@ function changePage(page) {
history.pushState("login", null, "login");
$(".page.pageLogin").addClass("active");
});
hideTestConfig();
TestConfig.hide();
hideSignOutButton();
}
}
@ -405,74 +397,10 @@ $(document).on("click", "#top .logo", (e) => {
changePage("test");
});
$(document).on("click", "#top .config .wordCount .text-button", (e) => {
const wrd = $(e.currentTarget).attr("wordCount");
if (wrd == "custom") {
CustomMode2Popup.show("words");
} else {
UpdateConfig.setWordCount(wrd);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .time .text-button", (e) => {
let mode = $(e.currentTarget).attr("timeConfig");
if (mode == "custom") {
CustomMode2Popup.show("time");
} else {
UpdateConfig.setTimeConfig(mode);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .quoteLength .text-button", (e) => {
let len = $(e.currentTarget).attr("quoteLength");
if (len == -2) {
UpdateConfig.setQuoteLength(-2, false, e.shiftKey);
QuoteSearchPopup.show();
} else {
if (len == -1) {
len = [0, 1, 2, 3];
}
UpdateConfig.setQuoteLength(len, false, e.shiftKey);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .customText .text-button", () => {
CustomTextPopup.show();
});
$(document).on("click", "#top .config .punctuationMode .text-button", () => {
UpdateConfig.togglePunctuation();
ManualRestart.set();
TestLogic.restart();
});
$(document).on("click", "#top .config .numbersMode .text-button", () => {
UpdateConfig.toggleNumbers();
ManualRestart.set();
TestLogic.restart();
});
$("#wordsWrapper").on("click", () => {
focusWords();
});
$(document).on("click", "#top .config .mode .text-button", (e) => {
if ($(e.currentTarget).hasClass("active")) return;
const mode = $(e.currentTarget).attr("mode");
UpdateConfig.setMode(mode);
ManualRestart.set();
TestLogic.restart();
});
$(document).on("click", "#top #menu .icon-button", (e) => {
if ($(e.currentTarget).hasClass("discord")) return;
if ($(e.currentTarget).hasClass("leaderboards")) {

View file

@ -0,0 +1,75 @@
import * as CustomMode2Popup from "./custom-mode2-popup";
import * as UpdateConfig from "./config";
import * as ManualRestart from "./manual-restart-tracker";
import * as TestLogic from "./test-logic";
import * as QuoteSearchPopup from "./quote-search-popup";
import * as CustomTextPopup from "./custom-text-popup";
export function show() {
$("#top .config").removeClass("hidden").css("opacity", 1);
}
export function hide() {
$("#top .config").css("opacity", 0).addClass("hidden");
}
$(document).on("click", "#top .config .wordCount .text-button", (e) => {
const wrd = $(e.currentTarget).attr("wordCount");
if (wrd == "custom") {
CustomMode2Popup.show("words");
} else {
UpdateConfig.setWordCount(wrd);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .time .text-button", (e) => {
let mode = $(e.currentTarget).attr("timeConfig");
if (mode == "custom") {
CustomMode2Popup.show("time");
} else {
UpdateConfig.setTimeConfig(mode);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .quoteLength .text-button", (e) => {
let len = $(e.currentTarget).attr("quoteLength");
if (len == -2) {
UpdateConfig.setQuoteLength(-2, false, e.shiftKey);
QuoteSearchPopup.show();
} else {
if (len == -1) {
len = [0, 1, 2, 3];
}
UpdateConfig.setQuoteLength(len, false, e.shiftKey);
ManualRestart.set();
TestLogic.restart();
}
});
$(document).on("click", "#top .config .customText .text-button", () => {
CustomTextPopup.show();
});
$(document).on("click", "#top .config .punctuationMode .text-button", () => {
UpdateConfig.togglePunctuation();
ManualRestart.set();
TestLogic.restart();
});
$(document).on("click", "#top .config .numbersMode .text-button", () => {
UpdateConfig.toggleNumbers();
ManualRestart.set();
TestLogic.restart();
});
$(document).on("click", "#top .config .mode .text-button", (e) => {
if ($(e.currentTarget).hasClass("active")) return;
const mode = $(e.currentTarget).attr("mode");
UpdateConfig.setMode(mode);
ManualRestart.set();
TestLogic.restart();
});