From caeccbc454389c693e4ca3bf147d51ee909c9671 Mon Sep 17 00:00:00 2001 From: Miodec Date: Sun, 16 Oct 2022 18:47:04 +0200 Subject: [PATCH] updated event handlers --- .../ts/popups/custom-test-duration-popup.ts | 2 +- frontend/src/ts/popups/quote-approve-popup.ts | 8 +- frontend/src/ts/popups/quote-search-popup.ts | 99 ++++++++++--------- frontend/src/ts/popups/quote-submit-popup.ts | 2 +- frontend/src/ts/popups/result-tags-popup.ts | 6 +- .../src/ts/popups/save-custom-text-popup.ts | 2 +- frontend/src/ts/popups/saved-texts-popup.ts | 10 +- 7 files changed, 67 insertions(+), 62 deletions(-) diff --git a/frontend/src/ts/popups/custom-test-duration-popup.ts b/frontend/src/ts/popups/custom-test-duration-popup.ts index a25a178e1..fccf23f78 100644 --- a/frontend/src/ts/popups/custom-test-duration-popup.ts +++ b/frontend/src/ts/popups/custom-test-duration-popup.ts @@ -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(); diff --git a/frontend/src/ts/popups/quote-approve-popup.ts b/frontend/src/ts/popups/quote-approve-popup.ts index cedc08862..c8c655140 100644 --- a/frontend/src/ts/popups/quote-approve-popup.ts +++ b/frontend/src/ts/popups/quote-approve-popup.ts @@ -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; diff --git a/frontend/src/ts/popups/quote-search-popup.ts b/frontend/src/ts/popups/quote-search-popup.ts index 073ec4a3a..8d7fb163a 100644 --- a/frontend/src/ts/popups/quote-search-popup.ts +++ b/frontend/src/ts/popups/quote-search-popup.ts @@ -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(); diff --git a/frontend/src/ts/popups/quote-submit-popup.ts b/frontend/src/ts/popups/quote-submit-popup.ts index 90cede5ca..51775efd2 100644 --- a/frontend/src/ts/popups/quote-submit-popup.ts +++ b/frontend/src/ts/popups/quote-submit-popup.ts @@ -100,7 +100,7 @@ $("#quoteSubmitPopupWrapper").on("mousedown", (e) => { } }); -$(document).on("click", "#quoteSubmitPopup #submitQuoteButton", () => { +$("#popups").on("click", "#quoteSubmitPopup #submitQuoteButton", () => { submitQuote(); }); diff --git a/frontend/src/ts/popups/result-tags-popup.ts b/frontend/src/ts/popups/result-tags-popup.ts index d501134f4..26ebdf6d3 100644 --- a/frontend/src/ts/popups/result-tags-popup.ts +++ b/frontend/src/ts/popups/result-tags-popup.ts @@ -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"); }); diff --git a/frontend/src/ts/popups/save-custom-text-popup.ts b/frontend/src/ts/popups/save-custom-text-popup.ts index eb094095b..dbb769b15 100644 --- a/frontend/src/ts/popups/save-custom-text-popup.ts +++ b/frontend/src/ts/popups/save-custom-text-popup.ts @@ -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(); }); diff --git a/frontend/src/ts/popups/saved-texts-popup.ts b/frontend/src/ts/popups/saved-texts-popup.ts index a2e99448d..f2fe76152 100644 --- a/frontend/src/ts/popups/saved-texts-popup.ts +++ b/frontend/src/ts/popups/saved-texts-popup.ts @@ -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`, () => {