js: Use .empty() instead of .html("").

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-08-17 15:30:47 -07:00
committed by Tim Abbott
parent de663184f3
commit e0b593f67e
15 changed files with 17 additions and 34 deletions

View File

@@ -302,6 +302,7 @@ test("handlers", ({override, mock_template}) => {
keys: [me.user_id, alice.user_id, fred.user_id], keys: [me.user_id, alice.user_id, fred.user_id],
}); });
activity.set_cursor_and_filter(); activity.set_cursor_and_filter();
$("#user_presences").empty = () => {};
$me_li = $.create("me stub"); $me_li = $.create("me stub");
$alice_li = $.create("alice stub"); $alice_li = $.create("alice stub");

View File

@@ -791,7 +791,7 @@ test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {
compose_validate.clear_topic_resolved_warning(); compose_validate.clear_topic_resolved_warning();
// Hack to make this empty for zjquery; this is conceptually done // Hack to make this empty for zjquery; this is conceptually done
// in the previous line. // in the previous line.
$error_area.html(""); $error_area.empty();
assert.ok(!$error_area.visible()); assert.ok(!$error_area.visible());
compose_state.set_message_type("stream"); compose_state.set_message_type("stream");

View File

@@ -44,6 +44,7 @@ const ListWidget = zrequire("list_widget");
function make_container() { function make_container() {
const $container = {}; const $container = {};
$container.empty = () => {};
// Make our append function just set a field we can // Make our append function just set a field we can
// check in our tests. // check in our tests.
@@ -159,9 +160,6 @@ run_test("scrolling", () => {
$simplebar_container: $scroll_container, $simplebar_container: $scroll_container,
}; };
$container.html = (html) => {
assert.equal(html, "");
};
ListWidget.create($container, items, opts); ListWidget.create($container, items, opts);
assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join("")); assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join(""));
@@ -213,9 +211,6 @@ run_test("not_scrolling", () => {
get_min_load_count, get_min_load_count,
}; };
$container.html = (html) => {
assert.equal(html, "");
};
ListWidget.create($container, items, opts); ListWidget.create($container, items, opts);
assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join("")); assert.deepEqual($container.$appended_data.html(), items.slice(0, 80).join(""));
@@ -251,9 +246,6 @@ run_test("filtering", () => {
$simplebar_container: $scroll_container, $simplebar_container: $scroll_container,
}; };
$container.html = (html) => {
assert.equal(html, "");
};
const widget = ListWidget.create($container, list, opts); const widget = ListWidget.create($container, list, opts);
let expected_html = let expected_html =
@@ -287,7 +279,6 @@ run_test("filtering", () => {
run_test("no filtering", () => { run_test("no filtering", () => {
const $container = make_container(); const $container = make_container();
const $scroll_container = make_scroll_container(); const $scroll_container = make_scroll_container();
$container.html = () => {};
let callback_called = false; let callback_called = false;
// Opts does not require a filter key. // Opts does not require a filter key.
@@ -365,9 +356,6 @@ run_test("wire up filter element", () => {
const $scroll_container = make_scroll_container(); const $scroll_container = make_scroll_container();
const $filter_element = make_filter_element(); const $filter_element = make_filter_element();
// We don't care about what gets drawn initially.
$container.html = () => {};
const opts = { const opts = {
filter: { filter: {
filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)), filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)),
@@ -388,8 +376,7 @@ run_test("sorting", () => {
const $sort_container = make_sort_container(); const $sort_container = make_sort_container();
let cleared; let cleared;
$container.html = (html) => { $container.empty = () => {
assert.equal(html, "");
cleared = true; cleared = true;
}; };
@@ -487,7 +474,6 @@ run_test("sorting", () => {
run_test("custom sort", () => { run_test("custom sort", () => {
const $container = make_container(); const $container = make_container();
const $scroll_container = make_scroll_container(); const $scroll_container = make_scroll_container();
$container.html = () => {};
const n42 = {x: 6, y: 7}; const n42 = {x: 6, y: 7};
const n43 = {x: 1, y: 43}; const n43 = {x: 1, y: 43};
@@ -538,7 +524,6 @@ run_test("clear_event_handlers", () => {
// We don't care about actual data for this test. // We don't care about actual data for this test.
const list = []; const list = [];
$container.html = () => {};
const opts = { const opts = {
name: "list-we-create-twice", name: "list-we-create-twice",
@@ -613,7 +598,6 @@ run_test("errors", () => {
}); });
blueslip.reset(); blueslip.reset();
$container.html = () => {};
blueslip.expect("error", "List item is not a string: 999"); blueslip.expect("error", "List item is not a string: 999");
ListWidget.create($container, list, { ListWidget.create($container, list, {
modifier: () => 999, modifier: () => 999,
@@ -647,7 +631,6 @@ run_test("sort helpers", () => {
run_test("replace_list_data w/filter update", () => { run_test("replace_list_data w/filter update", () => {
const $container = make_container(); const $container = make_container();
const $scroll_container = make_scroll_container(); const $scroll_container = make_scroll_container();
$container.html = () => {};
const list = [1, 2, 3, 4]; const list = [1, 2, 3, 4];
let num_updates = 0; let num_updates = 0;
@@ -722,7 +705,6 @@ run_test("render item", () => {
const $container = make_container(); const $container = make_container();
const $scroll_container = make_scroll_container(); const $scroll_container = make_scroll_container();
const INITIAL_RENDER_COUNT = 80; // Keep this in sync with the actual code. const INITIAL_RENDER_COUNT = 80; // Keep this in sync with the actual code.
$container.html = () => {};
let called = false; let called = false;
$scroll_container.find = (query) => { $scroll_container.find = (query) => {
const expected_queries = [ const expected_queries = [
@@ -840,7 +822,6 @@ run_test("Multiselect dropdown retain_selected_items", () => {
const list = ["one", "two", "three", "four"].map((x) => ({name: x, value: x})); const list = ["one", "two", "three", "four"].map((x) => ({name: x, value: x}));
const data = ["one"]; // Data initially selected. const data = ["one"]; // Data initially selected.
$container.html = () => {};
$container.find = (elem) => DropdownItem(elem); $container.find = (elem) => DropdownItem(elem);
// We essentially create fake jQuery functions // We essentially create fake jQuery functions

View File

@@ -359,7 +359,7 @@ run_test("spoiler-header-empty-fill", () => {
// Test that an empty header gets the default text applied (through i18n filter). // Test that an empty header gets the default text applied (through i18n filter).
const toggle_button_html = const toggle_button_html =
'<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>'; '<span class="spoiler-button" aria-expanded="false"><span class="spoiler-arrow"></span></span>';
$header.html(""); $header.empty();
rm.update_elements($content); rm.update_elements($content);
assert.equal(toggle_button_html + "<p>translated HTML: Spoiler</p>", $header.html()); assert.equal(toggle_button_html + "<p>translated HTML: Spoiler</p>", $header.html());
}); });

View File

@@ -59,6 +59,7 @@ function FakeElement(selector, opts) {
empty(arg) { empty(arg) {
if (arg === undefined) { if (arg === undefined) {
find_results.clear(); find_results.clear();
html = "";
} }
return $self; return $self;
}, },

View File

@@ -59,7 +59,7 @@ export class BuddyList extends BuddyListConf {
populate(opts) { populate(opts) {
this.render_count = 0; this.render_count = 0;
this.$container.html(""); this.$container.empty();
// We rely on our caller to give us items // We rely on our caller to give us items
// in already-sorted order. // in already-sorted order.

View File

@@ -337,7 +337,7 @@ function round_off_to_previous_multiple(number_to_round, multiple) {
} }
function reset_emoji_showcase() { function reset_emoji_showcase() {
$(".emoji-showcase-container").html(""); $(".emoji-showcase-container").empty();
} }
function update_emoji_showcase($focused_emoji) { function update_emoji_showcase($focused_emoji) {

View File

@@ -177,7 +177,7 @@ export function clear_for_testing() {
export function render_lightbox_list_images(preview_source) { export function render_lightbox_list_images(preview_source) {
if (!is_open) { if (!is_open) {
const images = Array.prototype.slice.call($(".focused_table .message_inline_image img")); const images = Array.prototype.slice.call($(".focused_table .message_inline_image img"));
const $image_list = $("#lightbox_overlay .image-list").html(""); const $image_list = $("#lightbox_overlay .image-list").empty();
for (const img of images) { for (const img of images) {
const src = img.getAttribute("src"); const src = img.getAttribute("src");

View File

@@ -278,7 +278,7 @@ export function create($container, list, opts) {
}; };
widget.clear = function () { widget.clear = function () {
$container.html(""); $container.empty();
meta.offset = 0; meta.offset = 0;
}; };

View File

@@ -973,7 +973,7 @@ export function register_click_handlers() {
emoji_name: "", emoji_name: "",
emoji_code: "", emoji_code: "",
success() { success() {
$(".info_popover_actions #status_message").html(""); $(".info_popover_actions #status_message").empty();
}, },
}); });
}); });

View File

@@ -286,7 +286,7 @@ export function add_custom_profile_fields_to_settings() {
} }
const element_id = "#profile-settings .custom-profile-fields-form"; const element_id = "#profile-settings .custom-profile-fields-form";
$(element_id).html(""); $(element_id).empty();
append_custom_profile_fields(element_id, people.my_current_user_id()); append_custom_profile_fields(element_id, people.my_current_user_id());
initialize_custom_user_type_fields(element_id, people.my_current_user_id(), true, true); initialize_custom_user_type_fields(element_id, people.my_current_user_id(), true, true);

View File

@@ -153,7 +153,7 @@ function clear_form_data() {
// Set default type "Short text" in field type dropdown // Set default type "Short text" in field type dropdown
$("#profile_field_type").val(field_types.SHORT_TEXT.id); $("#profile_field_type").val(field_types.SHORT_TEXT.id);
// Clear data from select field form // Clear data from select field form
$("#profile_field_choices").html(""); $("#profile_field_choices").empty();
create_choice_row($("#profile_field_choices")); create_choice_row($("#profile_field_choices"));
update_choice_delete_btn($("#profile_field_choices"), false); update_choice_delete_btn($("#profile_field_choices"), false);
$("#profile_field_choices_row").hide(); $("#profile_field_choices_row").hide();
@@ -314,7 +314,7 @@ function set_up_select_field_edit_form($profile_field_form, field_data) {
// Re-render field choices in edit form to load initial select data // Re-render field choices in edit form to load initial select data
const $choice_list = $profile_field_form.find(".edit_profile_field_choices_container"); const $choice_list = $profile_field_form.find(".edit_profile_field_choices_container");
$choice_list.off(); $choice_list.off();
$choice_list.html(""); $choice_list.empty();
const choices_data = parse_field_choices_from_field_data(field_data); const choices_data = parse_field_choices_from_field_data(field_data);

View File

@@ -31,7 +31,7 @@ export function reload() {
} }
const $user_groups_section = $("#user-groups").expectOne(); const $user_groups_section = $("#user-groups").expectOne();
$user_groups_section.html(""); $user_groups_section.empty();
populate_user_groups(); populate_user_groups();
} }

View File

@@ -588,7 +588,7 @@ export function show_edit_user_info_modal(user_id, from_user_info_popover) {
} }
const element = "#edit-user-form .custom-profile-field-form"; const element = "#edit-user-form .custom-profile-field-form";
$(element).html(""); $(element).empty();
settings_account.append_custom_profile_fields(element, user_id); settings_account.append_custom_profile_fields(element, user_id);
settings_account.initialize_custom_date_type_fields(element); settings_account.initialize_custom_date_type_fields(element);
fields_user_pills = settings_account.initialize_custom_user_type_fields( fields_user_pills = settings_account.initialize_custom_user_type_fields(

View File

@@ -117,7 +117,7 @@ function message_unhover() {
if ($current_message_hover === undefined) { if ($current_message_hover === undefined) {
return; return;
} }
$current_message_hover.find("span.edit_content").html(""); $current_message_hover.find("span.edit_content").empty();
$current_message_hover = undefined; $current_message_hover = undefined;
} }