diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 38ff713a4f..3960b08295 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -168,7 +168,7 @@ EXEMPT_FILES = make_set( "web/src/plotly.js.d.ts", "web/src/pm_list.ts", "web/src/pm_list_dom.ts", - "web/src/poll_modal.js", + "web/src/poll_modal.ts", "web/src/poll_widget.ts", "web/src/popover_menus.ts", "web/src/popover_menus_data.js", diff --git a/web/src/poll_modal.js b/web/src/poll_modal.ts similarity index 68% rename from web/src/poll_modal.js rename to web/src/poll_modal.ts index 316535f25c..5ddc243bca 100644 --- a/web/src/poll_modal.js +++ b/web/src/poll_modal.ts @@ -1,15 +1,15 @@ import $ from "jquery"; -import {Sortable} from "sortablejs"; +import SortableJS from "sortablejs"; import render_poll_modal_option from "../templates/poll_modal_option.hbs"; -function create_option_row($last_option_row_input) { +function create_option_row($last_option_row_input: JQuery): void { const row = render_poll_modal_option(); const $row_container = $last_option_row_input.closest(".simplebar-content"); $row_container.append(row); } -function add_option_row(e) { +function add_option_row(e: JQuery.TriggeredEvent): void { // if the option triggering the input event e is not the last, // that is, its next sibling has the class `option-row`, we // do not add a new option row and return from this function @@ -21,20 +21,20 @@ function add_option_row(e) { create_option_row($(e.target)); } -function delete_option_row(e) { +function delete_option_row(e: JQuery.ClickEvent): void { const $row = $(e.target).closest(".option-row"); $row.remove(); } -export function poll_options_setup() { +export function poll_options_setup(): void { const $poll_options_list = $("#add-poll-form .poll-options-list"); const $submit_button = $("#add-poll-modal .dialog_submit_button"); - const $question_input = $("#add-poll-form #poll-question-input"); + const $question_input = $("#add-poll-form input#poll-question-input"); // Disable the submit button if the question is empty. $submit_button.prop("disabled", true); $question_input.on("input", () => { - if ($question_input.val().trim() !== "") { + if ($question_input.val()!.trim() !== "") { $submit_button.prop("disabled", false); } else { $submit_button.prop("disabled", true); @@ -46,8 +46,10 @@ export function poll_options_setup() { // setTimeout is needed to here to give time for simplebar to initialise setTimeout(() => { - Sortable.create($("#add-poll-form .poll-options-list .simplebar-content")[0], { - onUpdate() {}, + SortableJS.create($("#add-poll-form .poll-options-list .simplebar-content")[0], { + onUpdate() { + // Do nothing on drag; the order is only processed on submission. + }, // We don't want the last (empty) row to be draggable, as a new row // is added on input event of the last row. filter: "input, .option-row:last-child", @@ -56,11 +58,11 @@ export function poll_options_setup() { }, 0); } -export function frame_poll_message_content() { - const question = $("#poll-question-input").val().trim(); - const options = $(".poll-option-input") +export function frame_poll_message_content(): string { + const question = $("input#poll-question-input").val()!.trim(); + const options = $("input.poll-option-input") .map(function () { - return $(this).val().trim(); + return $(this).val()!.trim(); }) .toArray() .filter(Boolean);