mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 21:33:40 +08:00
renamed module, added init function to keep the language input persistent
This commit is contained in:
parent
02fd9f658a
commit
232f6198fd
2 changed files with 28 additions and 19 deletions
|
@ -3,7 +3,7 @@ import * as ManualRestart from "./manual-restart-tracker";
|
|||
import * as Misc from "./misc";
|
||||
import * as Notifications from "./notifications";
|
||||
import * as TestLogic from "./test-logic";
|
||||
import * as WordFilter from "./word-filter-popup";
|
||||
import * as WordFilterPopup from "./word-filter-popup";
|
||||
|
||||
let wrapper = "#customTextPopupWrapper";
|
||||
let popup = "#customTextPopup";
|
||||
|
@ -157,5 +157,5 @@ $("#customTextPopup .apply").click(() => {
|
|||
});
|
||||
|
||||
$("#customTextPopup .wordfilter").click(() => {
|
||||
WordFilter.showWordFilterPopup();
|
||||
WordFilterPopup.show();
|
||||
});
|
||||
|
|
|
@ -1,50 +1,59 @@
|
|||
import * as Misc from "./misc";
|
||||
|
||||
export async function showWordFilterPopup() {
|
||||
let initialised = false;
|
||||
|
||||
async function init() {
|
||||
if (!initialised) {
|
||||
$("#languageList").empty();
|
||||
let LanguageList = await Misc.getLanguageList();
|
||||
LanguageList.forEach((language) => {
|
||||
let prettyLang = language;
|
||||
prettyLang = prettyLang.replace("_", " ");
|
||||
$("#languageList").append(`
|
||||
<option value=${language}>${prettyLang}</option>
|
||||
`);
|
||||
});
|
||||
initialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
export async function show() {
|
||||
await init();
|
||||
$("#wordFilterPopupWrapper").removeClass("hidden");
|
||||
$("#customTextPopupWrapper").addClass("hidden");
|
||||
$("#languageList").empty();
|
||||
let LanguageList = await Misc.getLanguageList();
|
||||
LanguageList.forEach((language) => {
|
||||
let prettyLang = language;
|
||||
prettyLang = prettyLang.replace("_", " ");
|
||||
$("#languageList").append(`
|
||||
<option value=${language}>${prettyLang}</option>
|
||||
`);
|
||||
});
|
||||
$("#languageList").select2({
|
||||
width: "100%",
|
||||
});
|
||||
}
|
||||
|
||||
function hideWordFilterPopup() {
|
||||
function hide() {
|
||||
$("#wordFilterPopupWrapper").addClass("hidden");
|
||||
$("#customTextPopupWrapper").removeClass("hidden");
|
||||
}
|
||||
|
||||
async function applyWordFilterPopup() {
|
||||
async function apply() {
|
||||
let language = $("#languageList").val();
|
||||
let filteredWords = await filter(language);
|
||||
let customText = "";
|
||||
filteredWords.forEach((word) => {
|
||||
customText += word + " ";
|
||||
});
|
||||
hideWordFilterPopup();
|
||||
hide();
|
||||
$("#customTextPopup textarea").val(customText);
|
||||
}
|
||||
|
||||
$("#wordFilterPopupWrapper").mousedown((e) => {
|
||||
if ($(e.target).attr("id") === "wordFilterPopupWrapper") {
|
||||
hideWordFilterPopup();
|
||||
hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("#wordFilterPopupWrapper .button").mousedown((e) => {
|
||||
$("#wordFilterPopupWrapper .wfload").removeClass("hidden");
|
||||
$("#wordFilterPopupWrapper .loadingIndicator").removeClass("hidden");
|
||||
$("#wordFilterPopupWrapper .button").addClass("hidden");
|
||||
setTimeout(() => {
|
||||
applyWordFilterPopup();
|
||||
$("#wordFilterPopupWrapper .wfload").addClass("hidden");
|
||||
apply();
|
||||
$("#wordFilterPopupWrapper .loadingIndicator").addClass("hidden");
|
||||
$("#wordFilterPopupWrapper .button").removeClass("hidden");
|
||||
}, 1);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue