Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
signup: Avoid slow jQuery :selected selector extension.
Anders Kaseorg081c0dc97f70
diff --git a/web/src/portico/signup.ts b/web/src/portico/signup.tsindex af0847835f8..20b13771ede 100644--- a/web/src/portico/signup.ts+++ b/web/src/portico/signup.ts@@ -307,13 +307,12 @@ $(() => {$(e.target).hide();});- $("#how-realm-creator-found-zulip select").on("change", function () {- const elements: Record<string, string> = {- Other: "how-realm-creator-found-zulip-other",- Advertisement: "how-realm-creator-found-zulip-where-ad",- "At an organization that's using it":- "how-realm-creator-found-zulip-which-organization",- };+ $<HTMLSelectElement>("#how-realm-creator-found-zulip select").on("change", function () {+ const elements = new Map([+ ["other", "how-realm-creator-found-zulip-other"],+ ["ad", "how-realm-creator-found-zulip-where-ad"],+ ["existing_user", "how-realm-creator-found-zulip-which-organization"],+ ]);const hideElement = (element: string): void => {const $element = $(`#${element}`);@@ -329,16 +328,15 @@ $(() => {};// Reset state- for (const element of Object.values(elements)) {+ for (const element of elements.values()) {if (element) {hideElement(element);}}// Show the additional input box if needed.- const selected_option = $("option:selected", this).text();- const selected_element = elements[selected_option];- if (selected_element) {+ const selected_element = elements.get(this.value);+ if (selected_element !== undefined) {showElement(selected_element);}});