mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-29 11:26:13 +08:00
updated event handlers
This commit is contained in:
parent
f43dc97ffb
commit
caeccbc454
7 changed files with 67 additions and 62 deletions
|
|
@ -139,7 +139,7 @@ $("#customTestDurationPopup .button").on("click", () => {
|
|||
apply();
|
||||
});
|
||||
|
||||
$(document).on("click", "#testConfig .time .textButton", (e) => {
|
||||
$("#testConfig").on("click", ".time .textButton", (e) => {
|
||||
const mode = $(e.currentTarget).attr("timeConfig");
|
||||
if (mode == "custom") {
|
||||
show();
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ $("#quoteApprovePopupWrapper .button.refreshList").on("click", () => {
|
|||
getQuotes();
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteApprovePopup .quote .undo", async (e) => {
|
||||
$("#popups").on("click", "#quoteApprovePopup .quote .undo", async (e) => {
|
||||
const index = parseInt($(e.target).closest(".quote").attr("id") as string);
|
||||
$(`#quoteApprovePopup .quote[id=${index}] .text`).val(quotes[index].text);
|
||||
$(`#quoteApprovePopup .quote[id=${index}] .source`).val(quotes[index].source);
|
||||
|
|
@ -132,7 +132,7 @@ $(document).on("click", "#quoteApprovePopup .quote .undo", async (e) => {
|
|||
updateQuoteLength(index);
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteApprovePopup .quote .approve", async (e) => {
|
||||
$("#popups").on("click", "#quoteApprovePopup .quote .approve", async (e) => {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
const index = parseInt($(e.target).closest(".quote").attr("id") as string);
|
||||
const dbid = $(e.target).closest(".quote").attr("dbid") as string;
|
||||
|
|
@ -158,7 +158,7 @@ $(document).on("click", "#quoteApprovePopup .quote .approve", async (e) => {
|
|||
updateList();
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteApprovePopup .quote .refuse", async (e) => {
|
||||
$("#popups").on("click", "#quoteApprovePopup .quote .refuse", async (e) => {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
const index = parseInt($(e.target).closest(".quote").attr("id") as string);
|
||||
const dbid = $(e.target).closest(".quote").attr("dbid") as string;
|
||||
|
|
@ -181,7 +181,7 @@ $(document).on("click", "#quoteApprovePopup .quote .refuse", async (e) => {
|
|||
updateList();
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteApprovePopup .quote .edit", async (e) => {
|
||||
$("#popups").on("click", "#quoteApprovePopup .quote .edit", async (e) => {
|
||||
if (!confirm("Are you sure?")) return;
|
||||
const index = parseInt($(e.target).closest(".quote").attr("id") as string);
|
||||
const dbid = $(e.target).closest(".quote").attr("dbid") as string;
|
||||
|
|
|
|||
|
|
@ -311,17 +311,17 @@ $("#quoteSearchPopupWrapper").on("click", (e) => {
|
|||
}
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteSearchPopup #gotoSubmitQuoteButton", () => {
|
||||
$("#popups").on("click", "#quoteSearchPopup #gotoSubmitQuoteButton", () => {
|
||||
hide(true);
|
||||
QuoteSubmitPopup.show(true);
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteSearchPopup #goToApproveQuotes", () => {
|
||||
$("#popups").on("click", "#quoteSearchPopup #goToApproveQuotes", () => {
|
||||
hide(true);
|
||||
QuoteApprovePopup.show(true);
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteSearchPopup .report", async (e) => {
|
||||
$("#popups").on("click", "#quoteSearchPopup .report", async (e) => {
|
||||
const quoteId = e.target.closest(".searchResult").id;
|
||||
const quoteIdSelectedForReport = parseInt(quoteId);
|
||||
|
||||
|
|
@ -335,57 +335,62 @@ $(document).on("click", "#quoteSearchPopup .report", async (e) => {
|
|||
});
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteSearchPopup .textButton.favorite", async (e) => {
|
||||
const quoteLang = Config.language;
|
||||
const quoteId = e.target.closest(".searchResult").id as string;
|
||||
$("#popups").on(
|
||||
"click",
|
||||
"#quoteSearchPopup .textButton.favorite",
|
||||
async (e) => {
|
||||
const quoteLang = Config.language;
|
||||
const quoteId = e.target.closest(".searchResult").id as string;
|
||||
|
||||
if (quoteLang === "" || quoteId === "") {
|
||||
Notifications.add("Could not get quote stats!", -1);
|
||||
return;
|
||||
}
|
||||
if (quoteLang === "" || quoteId === "") {
|
||||
Notifications.add("Could not get quote stats!", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
const $button = $(
|
||||
`#quoteSearchPopup .searchResult[id=${quoteId}] .textButton.favorite i`
|
||||
);
|
||||
const dbSnapshot = DB.getSnapshot();
|
||||
if (!dbSnapshot) return;
|
||||
|
||||
if ($button.hasClass("fas")) {
|
||||
// Remove from favorites
|
||||
Loader.show();
|
||||
const response = await Ape.users.removeQuoteFromFavorites(
|
||||
quoteLang,
|
||||
quoteId
|
||||
const $button = $(
|
||||
`#quoteSearchPopup .searchResult[id=${quoteId}] .textButton.favorite i`
|
||||
);
|
||||
Loader.hide();
|
||||
const dbSnapshot = DB.getSnapshot();
|
||||
if (!dbSnapshot) return;
|
||||
|
||||
Notifications.add(response.message, response.status === 200 ? 1 : -1);
|
||||
if ($button.hasClass("fas")) {
|
||||
// Remove from favorites
|
||||
Loader.show();
|
||||
const response = await Ape.users.removeQuoteFromFavorites(
|
||||
quoteLang,
|
||||
quoteId
|
||||
);
|
||||
Loader.hide();
|
||||
|
||||
if (response.status === 200) {
|
||||
$button.removeClass("fas").addClass("far");
|
||||
const quoteIndex = dbSnapshot.favoriteQuotes[quoteLang]?.indexOf(quoteId);
|
||||
dbSnapshot.favoriteQuotes[quoteLang]?.splice(quoteIndex, 1);
|
||||
}
|
||||
} else {
|
||||
// Add to favorites
|
||||
Loader.show();
|
||||
const response = await Ape.users.addQuoteToFavorites(quoteLang, quoteId);
|
||||
Loader.hide();
|
||||
Notifications.add(response.message, response.status === 200 ? 1 : -1);
|
||||
|
||||
Notifications.add(response.message, response.status === 200 ? 1 : -1);
|
||||
|
||||
if (response.status === 200) {
|
||||
$button.removeClass("far").addClass("fas");
|
||||
if (!dbSnapshot.favoriteQuotes[quoteLang]) {
|
||||
dbSnapshot.favoriteQuotes[quoteLang] = [];
|
||||
if (response.status === 200) {
|
||||
$button.removeClass("fas").addClass("far");
|
||||
const quoteIndex =
|
||||
dbSnapshot.favoriteQuotes[quoteLang]?.indexOf(quoteId);
|
||||
dbSnapshot.favoriteQuotes[quoteLang]?.splice(quoteIndex, 1);
|
||||
}
|
||||
dbSnapshot.favoriteQuotes[quoteLang]?.push(quoteId);
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
} else {
|
||||
// Add to favorites
|
||||
Loader.show();
|
||||
const response = await Ape.users.addQuoteToFavorites(quoteLang, quoteId);
|
||||
Loader.hide();
|
||||
|
||||
$(document).on("click", "#toggleShowFavorites", (e) => {
|
||||
Notifications.add(response.message, response.status === 200 ? 1 : -1);
|
||||
|
||||
if (response.status === 200) {
|
||||
$button.removeClass("far").addClass("fas");
|
||||
if (!dbSnapshot.favoriteQuotes[quoteLang]) {
|
||||
dbSnapshot.favoriteQuotes[quoteLang] = [];
|
||||
}
|
||||
dbSnapshot.favoriteQuotes[quoteLang]?.push(quoteId);
|
||||
}
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
);
|
||||
|
||||
$("#popups").on("click", "#quoteSearchPopup #toggleShowFavorites", (e) => {
|
||||
if (!Auth?.currentUser) {
|
||||
// Notifications.add("You need to be logged in to use this feature!", 0);
|
||||
return;
|
||||
|
|
@ -395,7 +400,7 @@ $(document).on("click", "#toggleShowFavorites", (e) => {
|
|||
searchForQuotes();
|
||||
});
|
||||
|
||||
$(document).on("click", "#testConfig .quoteLength .textButton", (e) => {
|
||||
$(".pageTest").on("click", "#testConfig .quoteLength .textButton", (e) => {
|
||||
const len = $(e.currentTarget).attr("quoteLength") ?? (0 as number);
|
||||
if (len == -2) {
|
||||
show();
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ $("#quoteSubmitPopupWrapper").on("mousedown", (e) => {
|
|||
}
|
||||
});
|
||||
|
||||
$(document).on("click", "#quoteSubmitPopup #submitQuoteButton", () => {
|
||||
$("#popups").on("click", "#quoteSubmitPopup #submitQuoteButton", () => {
|
||||
submitQuote();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ function updateActiveButtons(active: string[]): void {
|
|||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".pageAccount .group.history #resultEditTags", (f) => {
|
||||
$(".pageAccount").on("click", ".group.history #resultEditTags", (f) => {
|
||||
if ((DB.getSnapshot()?.tags?.length ?? 0) > 0) {
|
||||
const resultid = $(f.target).parents("span").attr("resultid") as string;
|
||||
const tags = $(f.target).parents("span").attr("tags") as string;
|
||||
|
|
@ -74,7 +74,7 @@ $(document).on("click", ".pageAccount .group.history #resultEditTags", (f) => {
|
|||
}
|
||||
});
|
||||
|
||||
$(document).on("click", ".pageTest .tags .editTagsButton", () => {
|
||||
$(".pageTest").on("click", ".tags .editTagsButton", () => {
|
||||
if (DB.getSnapshot()?.tags?.length ?? 0 > 0) {
|
||||
const resultid = $(".pageTest .tags .editTagsButton").attr(
|
||||
"result-id"
|
||||
|
|
@ -90,7 +90,7 @@ $(document).on("click", ".pageTest .tags .editTagsButton", () => {
|
|||
}
|
||||
});
|
||||
|
||||
$(document).on("click", "#resultEditTagsPanelWrapper .button.tag", (f) => {
|
||||
$("#popups").on("click", "#resultEditTagsPanelWrapper .button.tag", (f) => {
|
||||
$(f.target).toggleClass("active");
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ function save(): boolean {
|
|||
return true;
|
||||
}
|
||||
|
||||
$(document).on("click", `#saveCustomTextPopupWrapper .button.save`, () => {
|
||||
$("#popups").on("click", `#saveCustomTextPopupWrapper .button.save`, () => {
|
||||
if (save() === true) hide();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ function applySaved(name: string, long: boolean): void {
|
|||
$(`#customTextPopupWrapper textarea`).val(text.join(CustomText.delimiter));
|
||||
}
|
||||
|
||||
$(document).on(
|
||||
$("#popups").on(
|
||||
"click",
|
||||
`#savedTextsPopupWrapper .list .savedText .button.name`,
|
||||
(e) => {
|
||||
|
|
@ -83,7 +83,7 @@ $(document).on(
|
|||
}
|
||||
);
|
||||
|
||||
$(document).on(
|
||||
$("#popups").on(
|
||||
"click",
|
||||
`#savedTextsPopupWrapper .list .savedText .button.delete`,
|
||||
() => {
|
||||
|
|
@ -91,7 +91,7 @@ $(document).on(
|
|||
}
|
||||
);
|
||||
|
||||
$(document).on(
|
||||
$("#popups").on(
|
||||
"click",
|
||||
`#savedTextsPopupWrapper .listLong .savedText .button.name`,
|
||||
(e) => {
|
||||
|
|
@ -102,7 +102,7 @@ $(document).on(
|
|||
}
|
||||
);
|
||||
|
||||
$(document).on(
|
||||
$("#popups").on(
|
||||
"click",
|
||||
`#savedTextsPopupWrapper .listLong .savedText .button.resetProgress`,
|
||||
() => {
|
||||
|
|
@ -110,7 +110,7 @@ $(document).on(
|
|||
}
|
||||
);
|
||||
|
||||
$(document).on(
|
||||
$("#popups").on(
|
||||
"click",
|
||||
`#savedTextsPopupWrapper .listLong .savedText .button.delete`,
|
||||
() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue