web: Avoid slow jQuery :selected selector.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-05-01 21:59:01 -07:00
committed by Tim Abbott
parent ff2a7b775a
commit 8f2f2654a5
4 changed files with 17 additions and 16 deletions

View File

@@ -50,7 +50,7 @@ export const initialize = () => {
});
$("select[name=organization-type]").on("change", (e) => {
const string_value = $(e.currentTarget).find(":selected").attr("data-string-value");
const string_value = $(e.currentTarget.selectedOptions).attr("data-string-value");
helpers.update_discount_details(string_value);
});

View File

@@ -61,11 +61,11 @@ function set_results_notice(msg, level) {
}
function get_api_key_from_selected_bot() {
return $("#bot_name").children("option:selected").val();
return $("#bot_name").val();
}
function get_selected_integration_name() {
return $("#integration_name").children("option:selected").val();
return $("#integration_name").val();
}
function get_fixture_format(fixture_name) {
@@ -338,7 +338,7 @@ $(() => {
$("#integration_name").on("change", function () {
clear_elements(["custom_http_headers", "fixture_body", "fixture_name", "results_notice"]);
const integration_name = $(this).children("option:selected").val();
const integration_name = $(this.selectedOptions).val();
get_fixtures(integration_name);
update_url();
return;
@@ -346,7 +346,7 @@ $(() => {
$("#fixture_name").on("change", function () {
clear_elements(["fixture_body", "results_notice"]);
const fixture_name = $(this).children("option:selected").val();
const fixture_name = $(this.selectedOptions).val();
load_fixture_body(fixture_name);
return;
});

View File

@@ -198,14 +198,15 @@ $(() => {
}
function update_full_name_section() {
if (
$("#source_realm_select").length &&
$("#source_realm_select").find(":selected").val() !== ""
) {
if ($("#source_realm_select").length && $("#source_realm_select").val() !== "") {
$("#full_name_input_section").hide();
$("#profile_info_section").show();
const avatar_url = $("#source_realm_select").find(":selected").attr("data-avatar");
const full_name = $("#source_realm_select").find(":selected").attr("data-full-name");
const avatar_url = $($("#source_realm_select").prop("selectedOptions")).attr(
"data-avatar",
);
const full_name = $($("#source_realm_select").prop("selectedOptions")).attr(
"data-full-name",
);
$("#profile_full_name").text(full_name);
$("#id_full_name").val(full_name);
$("#profile_avatar").attr("src", avatar_url);

View File

@@ -206,12 +206,12 @@ export function add_a_new_bot() {
let create_avatar_widget;
function create_a_new_bot() {
const bot_type = $("#create_bot_type :selected").val();
const bot_type = $("#create_bot_type").val();
const full_name = $("#create_bot_name").val();
const short_name = $("#create_bot_short_name").val() || $("#create_bot_short_name").text();
const payload_url = $("#create_payload_url").val();
const interface_type = $("#create_interface_type").val();
const service_name = $("#select_service_name :selected").val();
const service_name = $("#select_service_name").val();
const formData = new FormData();
formData.append("csrfmiddlewaretoken", csrf_token);
@@ -267,7 +267,7 @@ export function add_a_new_bot() {
create_avatar_widget = avatar.build_bot_create_widget();
$("#create_bot_type").on("change", () => {
const bot_type = $("#create_bot_type :selected").val();
const bot_type = $("#create_bot_type").val();
// For "generic bot" or "incoming webhook" both these fields need not be displayed.
$("#service_name_list").hide();
$("#select_service_name").removeClass("required");
@@ -288,7 +288,7 @@ export function add_a_new_bot() {
$("#select_service_name").on("change", () => {
$("#config_inputbox").children().hide();
const selected_bot = $("#select_service_name :selected").val();
const selected_bot = $("#select_service_name").val();
$(`[name*='${CSS.escape(selected_bot)}']`).show();
});
}
@@ -382,7 +382,7 @@ export function show_edit_bot_info_modal(user_id, from_user_info_popover) {
if (bot_type === OUTGOING_WEBHOOK_BOT_TYPE) {
const service_payload_url = $("#edit_service_base_url").val();
const service_interface = $("#edit_service_interface :selected").val();
const service_interface = $("#edit_service_interface").val();
formData.append("service_payload_url", JSON.stringify(service_payload_url));
formData.append("service_interface", service_interface);
} else if (bot_type === EMBEDDED_BOT_TYPE && service !== undefined) {