js: Replace deprecated jQuery event trigger shorthand.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-07-20 12:24:26 -07:00
committed by Tim Abbott
parent 4e42137bd9
commit a9ca5f603b
60 changed files with 224 additions and 215 deletions

View File

@@ -157,7 +157,7 @@ exports.select_item_via_typeahead = function (field_selector, str, item) {
// Set the value and then send a bogus keyup event to trigger // Set the value and then send a bogus keyup event to trigger
// the typeahead. // the typeahead.
$(field_selector) $(field_selector)
.focus() .trigger("focus")
.val(str) .val(str)
.trigger($.Event("keyup", {which: 0})); .trigger($.Event("keyup", {which: 0}));

View File

@@ -345,7 +345,7 @@ casper.waitWhileSelector("#streams_list .input-append.notdisplayed", function ()
// Enter the search box and test highlighted suggestion navigation // Enter the search box and test highlighted suggestion navigation
casper.then(function () { casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
$(".stream-list-filter").expectOne().focus().trigger($.Event("click")); $(".stream-list-filter").expectOne().trigger("focus").trigger($.Event("click"));
}); });
}); });
@@ -399,7 +399,7 @@ casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
$(".stream-list-filter") $(".stream-list-filter")
.expectOne() .expectOne()
.focus() .trigger("focus")
.val("sCoT") .val("sCoT")
.trigger($.Event("input")) .trigger($.Event("input"))
.trigger($.Event("click")); .trigger($.Event("click"));
@@ -436,7 +436,7 @@ casper.then(function () {
// Clearing the list should give us back all the streams in the list // Clearing the list should give us back all the streams in the list
casper.then(function () { casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
$(".stream-list-filter").expectOne().focus().val("").trigger($.Event("input")); $(".stream-list-filter").expectOne().trigger("focus").val("").trigger($.Event("input"));
}); });
}); });
@@ -467,7 +467,7 @@ casper.waitForSelector(".input-append.notdisplayed", function () {
// We search for the beginning of "Verona", not case sensitive // We search for the beginning of "Verona", not case sensitive
casper.then(function () { casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
$(".stream-list-filter").expectOne().focus().val("ver").trigger($.Event("input")); $(".stream-list-filter").expectOne().trigger("focus").val("ver").trigger($.Event("input"));
}); });
}); });
@@ -519,7 +519,7 @@ casper.then(function () {
// Click on search icon // Click on search icon
casper.then(function () { casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
$("#user_filter_icon").expectOne().focus().trigger($.Event("click")); $("#user_filter_icon").expectOne().trigger("focus").trigger($.Event("click"));
}); });
}); });

View File

@@ -20,7 +20,7 @@ function toggle_test_star_message() {
return "cannot find star icon"; return "cannot find star icon";
} }
star_icon.click(); star_icon.trigger("click");
}); });
if (error) { if (error) {

View File

@@ -9,8 +9,8 @@ function then_edit_last_message() {
casper.then(function () { casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
var msg = $("#zhome .message_row").last(); var msg = $("#zhome .message_row").last();
msg.find(".info").click(); msg.find(".info").trigger("click");
$(".popover_edit_message").click(); $(".popover_edit_message").trigger("click");
}); });
}); });
casper.then(function () { casper.then(function () {
@@ -33,7 +33,7 @@ casper.then(function () {
var msg = $("#zhome .message_row").last(); var msg = $("#zhome .message_row").last();
msg.find(".message_edit_topic").val("edited"); msg.find(".message_edit_topic").val("edited");
msg.find(".message_edit_content").val("test edited"); msg.find(".message_edit_content").val("test edited");
msg.find(".message_edit_save").click(); msg.find(".message_edit_save").trigger("click");
}); });
}); });
@@ -54,7 +54,7 @@ casper.then(function () {
var msg = $("#zhome .message_row").last(); var msg = $("#zhome .message_row").last();
msg.find(".message_edit_topic").val("edited"); msg.find(".message_edit_topic").val("edited");
msg.find(".message_edit_content").val("/me test edited one line with me"); msg.find(".message_edit_content").val("/me test edited one line with me");
msg.find(".message_edit_save").click(); msg.find(".message_edit_save").trigger("click");
}); });
}); });
@@ -76,7 +76,7 @@ casper.then(function () {
casper.evaluate(function () { casper.evaluate(function () {
var msg = $("#zhome .message_row").last(); var msg = $("#zhome .message_row").last();
msg.find(".message_edit_content").val("test edited pm"); msg.find(".message_edit_content").val("test edited pm");
msg.find(".message_edit_save").click(); msg.find(".message_edit_save").trigger("click");
}); });
}); });

View File

@@ -302,7 +302,7 @@ function get_suggestions(str) {
casper.then(function () { casper.then(function () {
casper.evaluate(function (str) { casper.evaluate(function (str) {
$(".create_default_stream") $(".create_default_stream")
.focus() .trigger("focus")
.val(str) .val(str)
.trigger($.Event("keyup", {which: 0})); .trigger($.Event("keyup", {which: 0}));
}, str); }, str);

View File

@@ -15,8 +15,8 @@ casper.then(function () {
}); });
last_message_id = this.evaluate(function () { last_message_id = this.evaluate(function () {
var msg = $("#zhome .message_row").last(); var msg = $("#zhome .message_row").last();
msg.find(".info").click(); msg.find(".info").trigger("click");
$(".delete_message").click(); $(".delete_message").trigger("click");
return msg.attr("id"); return msg.attr("id");
}); });
}); });

View File

@@ -243,7 +243,7 @@ function reset_setup() {
reset_setup(); reset_setup();
run_test("presence_list_full_update", () => { run_test("presence_list_full_update", () => {
$(".user-list-filter").focus(); $(".user-list-filter").trigger("focus");
compose_state.private_message_recipient = () => fred.email; compose_state.private_message_recipient = () => fred.email;
compose_fade.set_focused_recipient("private"); compose_fade.set_focused_recipient("private");
@@ -603,7 +603,7 @@ run_test("escape_search", () => {
reset_setup(); reset_setup();
run_test("initiate_search", () => { run_test("initiate_search", () => {
$(".user-list-filter").blur(); $(".user-list-filter").trigger("blur");
simulate_right_column_buddy_list(); simulate_right_column_buddy_list();
activity.initiate_search(); activity.initiate_search();
assert.equal($(".column-right").hasClass("expanded"), true); assert.equal($(".column-right").hasClass("expanded"), true);
@@ -627,9 +627,9 @@ run_test("toggle_filter_display", () => {
}); });
run_test("searching", () => { run_test("searching", () => {
$(".user-list-filter").focus(); $(".user-list-filter").trigger("focus");
assert.equal(activity.searching(), true); assert.equal(activity.searching(), true);
$(".user-list-filter").blur(); $(".user-list-filter").trigger("blur");
assert.equal(activity.searching(), false); assert.equal(activity.searching(), false);
}); });

View File

@@ -11,7 +11,7 @@ $("body").append = noop;
$(input).val = (arg) => { $(input).val = (arg) => {
assert.equal(arg, "iago@zulip.com"); assert.equal(arg, "iago@zulip.com");
return { return {
select: noop, trigger: noop,
}; };
}; };

View File

@@ -42,8 +42,10 @@ run_test("basics", () => {
return i; return i;
}; };
self.focus = function () { self.trigger = function (type) {
focused_tab = i; if (type === "focus") {
focused_tab = i;
}
}; };
tabs.push(self); tabs.push(self);

View File

@@ -196,7 +196,7 @@ run_test("validate", () => {
set_global("$", global.make_zjquery()); set_global("$", global.make_zjquery());
$("#compose-send-button").prop("disabled", false); $("#compose-send-button").prop("disabled", false);
$("#compose-send-button").focus(); $("#compose-send-button").trigger("focus");
$("#sending-indicator").hide(); $("#sending-indicator").hide();
const pm_pill_container = $.create("fake-pm-pill-container"); const pm_pill_container = $.create("fake-pm-pill-container");
@@ -588,7 +588,7 @@ run_test("markdown_shortcuts", () => {
run_test("send_message_success", () => { run_test("send_message_success", () => {
$("#compose-textarea").val("foobarfoobar"); $("#compose-textarea").val("foobarfoobar");
$("#compose-textarea").blur(); $("#compose-textarea").trigger("blur");
$("#compose-send-status").show(); $("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled"); $("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show(); $("#sending-indicator").show();
@@ -686,7 +686,7 @@ run_test("send_message", () => {
// Setting message content with a host server link and we will assert // Setting message content with a host server link and we will assert
// later that this has been converted to a relative link. // later that this has been converted to a relative link.
$("#compose-textarea").val("[foobar]" + "(https://foo.com/user_uploads/123456)"); $("#compose-textarea").val("[foobar]" + "(https://foo.com/user_uploads/123456)");
$("#compose-textarea").blur(); $("#compose-textarea").trigger("blur");
$("#compose-send-status").show(); $("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled"); $("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show(); $("#sending-indicator").show();
@@ -738,7 +738,7 @@ run_test("send_message", () => {
(function test_error_codepath_local_id_undefined() { (function test_error_codepath_local_id_undefined() {
stub_state = initialize_state_stub_dict(); stub_state = initialize_state_stub_dict();
$("#compose-textarea").val("foobarfoobar"); $("#compose-textarea").val("foobarfoobar");
$("#compose-textarea").blur(); $("#compose-textarea").trigger("blur");
$("#compose-send-status").show(); $("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled"); $("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show(); $("#sending-indicator").show();
@@ -794,7 +794,7 @@ run_test("enter_with_preview_open", () => {
assert(send_message_called); assert(send_message_called);
page_params.enter_sends = false; page_params.enter_sends = false;
$("#compose-textarea").blur(); $("#compose-textarea").trigger("blur");
compose.enter_with_preview_open(); compose.enter_with_preview_open();
assert($("#compose-textarea").is_focused()); assert($("#compose-textarea").is_focused());
@@ -814,7 +814,7 @@ run_test("finish", () => {
(function test_when_compose_validation_fails() { (function test_when_compose_validation_fails() {
$("#compose_invite_users").show(); $("#compose_invite_users").show();
$("#compose-send-button").prop("disabled", false); $("#compose-send-button").prop("disabled", false);
$("#compose-send-button").focus(); $("#compose-send-button").trigger("focus");
$("#sending-indicator").hide(); $("#sending-indicator").hide();
$("#compose-textarea").off("select"); $("#compose-textarea").off("select");
$("#compose-textarea").val(""); $("#compose-textarea").val("");

View File

@@ -409,7 +409,7 @@ run_test("focus_in_empty_compose", () => {
compose_state.composing = return_true; compose_state.composing = return_true;
$("#compose-textarea").val(""); $("#compose-textarea").val("");
$("#compose-textarea").focus(); $("#compose-textarea").trigger("focus");
assert(compose_state.focus_in_empty_compose()); assert(compose_state.focus_in_empty_compose());
compose_state.composing = return_false; compose_state.composing = return_false;
@@ -418,7 +418,7 @@ run_test("focus_in_empty_compose", () => {
$("#compose-textarea").val("foo"); $("#compose-textarea").val("foo");
assert(!compose_state.focus_in_empty_compose()); assert(!compose_state.focus_in_empty_compose());
$("#compose-textarea").blur(); $("#compose-textarea").trigger("blur");
assert(!compose_state.focus_in_empty_compose()); assert(!compose_state.focus_in_empty_compose());
}); });

View File

@@ -50,14 +50,6 @@ function make_textbox(s) {
return widget.pos; return widget.pos;
}; };
widget.focus = function () {
widget.focused = true;
};
widget.blur = function () {
widget.focused = false;
};
widget.val = function (new_val) { widget.val = function (new_val) {
if (new_val) { if (new_val) {
widget.s = new_val; widget.s = new_val;
@@ -66,8 +58,12 @@ function make_textbox(s) {
} }
}; };
widget.trigger = function () { widget.trigger = function (type) {
return; if (type === "focus") {
widget.focused = true;
} else if (type === "blur") {
widget.focused = false;
}
}; };
return widget; return widget;
@@ -98,21 +94,21 @@ run_test("smart_insert", () => {
assert.equal(textbox.val(), "abc :smile: "); assert.equal(textbox.val(), "abc :smile: ");
assert(textbox.focused); assert(textbox.focused);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":airplane:"); compose_ui.smart_insert(textbox, ":airplane:");
assert.equal(textbox.insert_text, ":airplane: "); assert.equal(textbox.insert_text, ":airplane: ");
assert.equal(textbox.val(), "abc :smile: :airplane: "); assert.equal(textbox.val(), "abc :smile: :airplane: ");
assert(textbox.focused); assert(textbox.focused);
textbox.caret(0); textbox.caret(0);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":octopus:"); compose_ui.smart_insert(textbox, ":octopus:");
assert.equal(textbox.insert_text, ":octopus: "); assert.equal(textbox.insert_text, ":octopus: ");
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: "); assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: ");
assert(textbox.focused); assert(textbox.focused);
textbox.caret(textbox.val().length); textbox.caret(textbox.val().length);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":heart:"); compose_ui.smart_insert(textbox, ":heart:");
assert.equal(textbox.insert_text, ":heart: "); assert.equal(textbox.insert_text, ":heart: ");
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: :heart: "); assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: :heart: ");
@@ -121,7 +117,7 @@ run_test("smart_insert", () => {
// Test handling of spaces for ```quote // Test handling of spaces for ```quote
textbox = make_textbox(""); textbox = make_textbox("");
textbox.caret(0); textbox.caret(0);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, "```quote\nquoted message\n```\n"); compose_ui.smart_insert(textbox, "```quote\nquoted message\n```\n");
assert.equal(textbox.insert_text, "```quote\nquoted message\n```\n"); assert.equal(textbox.insert_text, "```quote\nquoted message\n```\n");
assert.equal(textbox.val(), "```quote\nquoted message\n```\n"); assert.equal(textbox.val(), "```quote\nquoted message\n```\n");
@@ -129,7 +125,7 @@ run_test("smart_insert", () => {
textbox = make_textbox(""); textbox = make_textbox("");
textbox.caret(0); textbox.caret(0);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, "[Quoting…]\n"); compose_ui.smart_insert(textbox, "[Quoting…]\n");
assert.equal(textbox.insert_text, "[Quoting…]\n"); assert.equal(textbox.insert_text, "[Quoting…]\n");
assert.equal(textbox.val(), "[Quoting…]\n"); assert.equal(textbox.val(), "[Quoting…]\n");
@@ -137,7 +133,7 @@ run_test("smart_insert", () => {
textbox = make_textbox("abc"); textbox = make_textbox("abc");
textbox.caret(3); textbox.caret(3);
textbox.blur(); textbox.trigger("blur");
compose_ui.smart_insert(textbox, " test with space"); compose_ui.smart_insert(textbox, " test with space");
assert.equal(textbox.insert_text, " test with space "); assert.equal(textbox.insert_text, " test with space ");
assert.equal(textbox.val(), "abc test with space "); assert.equal(textbox.val(), "abc test with space ");

View File

@@ -777,7 +777,7 @@ run_test("initialize", () => {
const click_event = {type: "click", target: "#doesnotmatter"}; const click_event = {type: "click", target: "#doesnotmatter"};
options.query = "othello"; options.query = "othello";
// Focus lost (caused by the click event in the typeahead list) // Focus lost (caused by the click event in the typeahead list)
$("#private_message_recipient").blur(); $("#private_message_recipient").trigger("blur");
actual_value = options.updater(othello, click_event); actual_value = options.updater(othello, click_event);
assert.equal(appended_name, "Othello, the Moor of Venice"); assert.equal(appended_name, "Othello, the Moor of Venice");
@@ -969,6 +969,7 @@ run_test("initialize", () => {
// handle_keydown() // handle_keydown()
let event = { let event = {
type: "keydown",
keyCode: 13, keyCode: 13,
target: { target: {
id: "stream_message_recipient_stream", id: "stream_message_recipient_stream",
@@ -979,7 +980,7 @@ run_test("initialize", () => {
$("#stream_message_recipient_topic").data = function () { $("#stream_message_recipient_topic").data = function () {
return {typeahead: {shown: true}}; return {typeahead: {shown: true}};
}; };
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
const stub_typeahead_hidden = function () { const stub_typeahead_hidden = function () {
return {typeahead: {shown: false}}; return {typeahead: {shown: false}};
@@ -988,17 +989,17 @@ run_test("initialize", () => {
$("#stream_message_recipient_stream").data = stub_typeahead_hidden; $("#stream_message_recipient_stream").data = stub_typeahead_hidden;
$("#private_message_recipient").data = stub_typeahead_hidden; $("#private_message_recipient").data = stub_typeahead_hidden;
$("#compose-textarea").data = stub_typeahead_hidden; $("#compose-textarea").data = stub_typeahead_hidden;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.keyCode = undefined; event.keyCode = undefined;
event.which = 9; event.which = 9;
event.shiftKey = false; event.shiftKey = false;
event.target.id = "subject"; event.target.id = "subject";
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.target.id = "compose-textarea"; event.target.id = "compose-textarea";
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.target.id = "some_non_existing_id"; event.target.id = "some_non_existing_id";
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
// Setup jquery functions used in compose_textarea enter // Setup jquery functions used in compose_textarea enter
// handler. // handler.
@@ -1015,7 +1016,7 @@ run_test("initialize", () => {
event.keyCode = 13; event.keyCode = 13;
event.target.id = "stream_message_recipient_topic"; event.target.id = "stream_message_recipient_topic";
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.target.id = "compose-textarea"; event.target.id = "compose-textarea";
page_params.enter_sends = false; page_params.enter_sends = false;
event.metaKey = true; event.metaKey = true;
@@ -1024,50 +1025,52 @@ run_test("initialize", () => {
compose_finish_called = true; compose_finish_called = true;
}; };
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
assert(compose_finish_called); assert(compose_finish_called);
event.metaKey = false; event.metaKey = false;
event.ctrlKey = true; event.ctrlKey = true;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
page_params.enter_sends = true; page_params.enter_sends = true;
event.ctrlKey = false; event.ctrlKey = false;
event.altKey = true; event.altKey = true;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
// Cover case where there's a least one character there. // Cover case where there's a least one character there.
range_length = 2; range_length = 2;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.altKey = false; event.altKey = false;
event.metaKey = true; event.metaKey = true;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.target.id = "private_message_recipient"; event.target.id = "private_message_recipient";
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
event.keyCode = 42; event.keyCode = 42;
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
// handle_keyup() // handle_keyup()
event = { event = {
type: "keydown",
keyCode: 13, keyCode: 13,
target: { target: {
id: "stream_message_recipient_stream", id: "stream_message_recipient_stream",
}, },
preventDefault: noop, preventDefault: noop,
}; };
// We execute .keydown() in order to make nextFocus !== false // We trigger keydown in order to make nextFocus !== false
$("#stream_message_recipient_topic").data = function () { $("#stream_message_recipient_topic").data = function () {
return {typeahead: {shown: true}}; return {typeahead: {shown: true}};
}; };
$("form#send_message_form").keydown(event); $("form#send_message_form").trigger(event);
$("#stream_message_recipient_topic").off("mouseup"); $("#stream_message_recipient_topic").off("mouseup");
$("form#send_message_form").keyup(event); event.type = "keyup";
$("form#send_message_form").trigger(event);
event.keyCode = undefined; event.keyCode = undefined;
event.which = 9; event.which = 9;
event.shiftKey = false; event.shiftKey = false;
$("form#send_message_form").keyup(event); $("form#send_message_form").trigger(event);
event.keyCode = 42; event.keyCode = 42;
$("form#send_message_form").keyup(event); $("form#send_message_form").trigger(event);
// select_on_focus() // select_on_focus()
@@ -1084,14 +1087,14 @@ run_test("initialize", () => {
$("#enter_sends").is = function () { $("#enter_sends").is = function () {
return false; return false;
}; };
$("#enter_sends").click(); $("#enter_sends").trigger("click");
// Now we re-run both .initialize() and the click handler, this time // Now we re-run both .initialize() and the click handler, this time
// with enter_sends: page_params.enter_sends being true // with enter_sends: page_params.enter_sends being true
$("#enter_sends").is = function () { $("#enter_sends").is = function () {
return true; return true;
}; };
$("#enter_sends").click(); $("#enter_sends").trigger("click");
$("#stream_message_recipient_stream").off("focus"); $("#stream_message_recipient_stream").off("focus");
$("#stream_message_recipient_topic").off("focus"); $("#stream_message_recipient_topic").off("focus");

View File

@@ -236,13 +236,17 @@ run_test("arrows on pills", () => {
const pill_stub = { const pill_stub = {
prev: () => ({ prev: () => ({
focus: () => { trigger: (type) => {
prev_focused = true; if (type === "focus") {
prev_focused = true;
}
}, },
}), }),
next: () => ({ next: () => ({
focus: () => { trigger: (type) => {
next_focused = true; if (type === "focus") {
next_focused = true;
}
}, },
}), }),
}; };
@@ -274,8 +278,10 @@ run_test("left arrow on input", () => {
container.set_find_results(".pill", { container.set_find_results(".pill", {
last: () => ({ last: () => ({
focus: () => { trigger: (type) => {
last_pill_focused = true; if (type === "focus") {
last_pill_focused = true;
}
}, },
}), }),
}); });
@@ -411,8 +417,10 @@ run_test("insert_remove", () => {
let next_pill_focused = false; let next_pill_focused = false;
const next_pill_stub = { const next_pill_stub = {
focus: () => { trigger: (type) => {
next_pill_focused = true; if (type === "focus") {
next_pill_focused = true;
}
}, },
}; };
@@ -449,8 +457,10 @@ run_test("exit button on pill", () => {
let next_pill_focused = false; let next_pill_focused = false;
const next_pill_stub = { const next_pill_stub = {
focus: () => { trigger: (type) => {
next_pill_focused = true; if (type === "focus") {
next_pill_focused = true;
}
}, },
}; };

View File

@@ -14,24 +14,26 @@ run_test("test_early_returns", () => {
}; };
keydown_util.handle(opts); keydown_util.handle(opts);
const keydown_f = stub.keydown;
const e1 = { const e1 = {
type: "keydown",
which: 17, // not in keys which: 17, // not in keys
}; };
keydown_f(e1); stub.trigger(e1);
const e2 = { const e2 = {
type: "keydown",
which: 13, // no handler which: 13, // no handler
}; };
keydown_f(e2); stub.trigger(e2);
const e3 = { const e3 = {
type: "keydown",
which: 37, which: 37,
altKey: true, // let browser handle altKey: true, // let browser handle
}; };
keydown_f(e3); stub.trigger(e3);
}); });

View File

@@ -31,7 +31,7 @@ global.patch_builtin("setTimeout", (func) => func());
run_test("clear_search_form", () => { run_test("clear_search_form", () => {
$("#search_query").val("noise"); $("#search_query").val("noise");
$("#search_query").focus(); $("#search_query").trigger("focus");
$(".search_button").prop("disabled", false); $(".search_button").prop("disabled", false);
search.clear_search_form(); search.clear_search_form();

View File

@@ -140,11 +140,7 @@ run_test("test tab clicks", () => {
set_up(); set_up();
function click_on_tab(tab_elem) { function click_on_tab(tab_elem) {
const e = { tab_elem.trigger("click");
preventDefault: () => {},
stopPropagation: () => {},
};
tab_elem.click(e);
} }
const tabs = { const tabs = {

View File

@@ -131,11 +131,11 @@ run_test("clicks", () => {
assert(!state.keydown); assert(!state.keydown);
// But we can simulate clicks. // But we can simulate clicks.
$("#widget1").click(); $("#widget1").trigger("click");
assert.equal(state.clicked, true); assert.equal(state.clicked, true);
// and keydown // and keydown
$(".some-class").keydown(); $(".some-class").trigger("keydown");
assert.equal(state.keydown, true); assert.equal(state.keydown, true);
}); });

View File

@@ -15,7 +15,7 @@ exports.render_alert_words_ui = function () {
} }
// Focus new alert word name text box. // Focus new alert word name text box.
$("#create_alert_word_name").focus(); $("#create_alert_word_name").trigger("focus");
}; };
function update_alert_word_status(status_text, is_error) { function update_alert_word_status(status_text, is_error) {

View File

@@ -9,7 +9,7 @@ function convert_enter_to_click(e) {
const key = e.which; const key = e.which;
if (key === 13) { if (key === 13) {
// enter // enter
$(e.currentTarget).click(); $(e.currentTarget).trigger("click");
} }
} }
@@ -200,7 +200,7 @@ exports.initialize = function () {
if (page_params.realm_allow_edit_history) { if (page_params.realm_allow_edit_history) {
message_edit_history.show_history(message); message_edit_history.show_history(message);
message_history_cancel_btn.focus(); message_history_cancel_btn.trigger("focus");
} }
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
@@ -601,7 +601,7 @@ exports.initialize = function () {
notifications.register_click_handlers(); notifications.register_click_handlers();
$("body").on("click", ".logout_button", () => { $("body").on("click", ".logout_button", () => {
$("#logout_form").submit(); $("#logout_form").trigger("submit");
}); });
$(".restart_get_events_button").on("click", () => { $(".restart_get_events_button").on("click", () => {
@@ -757,24 +757,24 @@ exports.initialize = function () {
// disable the draggability for left-sidebar components // disable the draggability for left-sidebar components
$("#stream_filters, #global_filters").on("dragstart", (e) => { $("#stream_filters, #global_filters").on("dragstart", (e) => {
e.target.blur(); e.target.trigger("blur");
return false; return false;
}); });
// Chrome focuses an element when dragging it which can be confusing when // Chrome focuses an element when dragging it which can be confusing when
// users involuntarily drag something and we show them the focus outline. // users involuntarily drag something and we show them the focus outline.
$("body").on("dragstart", "a", (e) => e.target.blur()); $("body").on("dragstart", "a", (e) => e.target.trigger("blur"));
// Don't focus links on middle click. // Don't focus links on middle click.
$("body").on("mouseup", "a", (e) => { $("body").on("mouseup", "a", (e) => {
if (e.which === 2) { if (e.which === 2) {
// middle click // middle click
e.target.blur(); e.target.trigger("blur");
} }
}); });
// Don't focus links on context menu. // Don't focus links on context menu.
$("body").on("contextmenu", "a", (e) => e.target.blur()); $("body").on("contextmenu", "a", (e) => e.target.trigger("blur"));
(function () { (function () {
const map = { const map = {
@@ -797,7 +797,7 @@ exports.initialize = function () {
$(this).text($(this).attr("data-prev-text")); $(this).text($(this).attr("data-prev-text"));
$("[data-make-editable]").html(""); $("[data-make-editable]").html("");
} else if (e.which === 13) { } else if (e.which === 13) {
$(this).siblings(".checkmark").click(); $(this).siblings(".checkmark").trigger("click");
} }
}); });
@@ -945,7 +945,7 @@ exports.initialize = function () {
if (compose_state.composing()) { if (compose_state.composing()) {
if ($(e.target).closest("a").length > 0) { if ($(e.target).closest("a").length > 0) {
// Refocus compose message text box if link is clicked // Refocus compose message text box if link is clicked
$("#compose-textarea").focus(); $("#compose-textarea").trigger("focus");
return; return;
} else if ( } else if (
!window.getSelection().toString() && !window.getSelection().toString() &&

View File

@@ -7,7 +7,7 @@ exports.status_classes = "alert-error alert-success alert-info alert-warning";
exports.autofocus = function (selector) { exports.autofocus = function (selector) {
$(() => { $(() => {
$(selector).focus(); $(selector).trigger("focus");
}); });
}; };
@@ -90,7 +90,7 @@ exports.copy_data_attribute_value = function (elem, key) {
// attribute of the element to clipboard // attribute of the element to clipboard
const temp = $(document.createElement("input")); const temp = $(document.createElement("input"));
$("body").append(temp); $("body").append(temp);
temp.val(elem.data(key)).select(); temp.val(elem.data(key)).trigger("select");
document.execCommand("copy"); document.execCommand("copy");
temp.remove(); temp.remove();
elem.fadeOut(250); elem.fadeOut(250);

View File

@@ -65,7 +65,7 @@ exports.toggle = function (opts) {
} }
if (!opts.child_wants_focus) { if (!opts.child_wants_focus) {
elem.focus(); elem.trigger("focus");
} }
} }

View File

@@ -259,7 +259,7 @@ function compose_error(error_text, bad_input) {
$("#compose-send-button").prop("disabled", false); $("#compose-send-button").prop("disabled", false);
$("#sending-indicator").hide(); $("#sending-indicator").hide();
if (bad_input !== undefined) { if (bad_input !== undefined) {
bad_input.focus().select(); bad_input.trigger("focus").trigger("select");
} }
} }
@@ -284,14 +284,14 @@ function compose_not_subscribed_error(error_text, bad_input) {
$("#sending-indicator").hide(); $("#sending-indicator").hide();
$(".compose-send-status-close").hide(); $(".compose-send-status-close").hide();
if (bad_input !== undefined) { if (bad_input !== undefined) {
bad_input.focus().select(); bad_input.trigger("focus").trigger("select");
} }
} }
exports.nonexistent_stream_reply_error = nonexistent_stream_reply_error; exports.nonexistent_stream_reply_error = nonexistent_stream_reply_error;
function clear_compose_box() { function clear_compose_box() {
$("#compose-textarea").val("").focus(); $("#compose-textarea").val("").trigger("focus");
drafts.delete_draft_after_send(); drafts.delete_draft_after_send();
compose_ui.autosize_textarea(); compose_ui.autosize_textarea();
$("#compose-send-status").hide(0); $("#compose-send-status").hide(0);
@@ -379,7 +379,7 @@ exports.enter_with_preview_open = function () {
exports.finish(); exports.finish();
} else { } else {
// Otherwise, we return to the compose box and focus it // Otherwise, we return to the compose box and focus it
$("#compose-textarea").focus(); $("#compose-textarea").trigger("focus");
} }
}; };
@@ -696,7 +696,7 @@ function validate_private_message() {
} }
exports.validate = function () { exports.validate = function () {
$("#compose-send-button").attr("disabled", "disabled").blur(); $("#compose-send-button").attr("disabled", "disabled").trigger("blur");
const message_content = compose_state.message_content(); const message_content = compose_state.message_content();
if (reminder.is_deferred_delivery(message_content)) { if (reminder.is_deferred_delivery(message_content)) {
show_sending_indicator(i18n.t("Scheduling...")); show_sending_indicator(i18n.t("Scheduling..."));

View File

@@ -1,7 +1,7 @@
const autosize = require("autosize"); const autosize = require("autosize");
exports.blur_textarea = function () { exports.blur_textarea = function () {
$(".message_comp").find("input, textarea, button").blur(); $(".message_comp").find("input, textarea, button").trigger("blur");
}; };
function hide_box() { function hide_box() {
@@ -45,7 +45,7 @@ exports.set_focus = function (msg_type, opts) {
if (window.getSelection().toString() === "" || opts.trigger !== "message click") { if (window.getSelection().toString() === "" || opts.trigger !== "message click") {
const elt = $(focus_area); const elt = $(focus_area);
elt.focus().select(); elt.trigger("focus").trigger("select");
} }
}; };
@@ -384,7 +384,7 @@ exports.on_topic_narrow = function () {
compose_state.topic(narrow_state.topic()); compose_state.topic(narrow_state.topic());
compose_fade.set_focused_recipient("stream"); compose_fade.set_focused_recipient("stream");
compose_fade.update_message_list(); compose_fade.update_message_list();
$("#compose-textarea").focus().select(); $("#compose-textarea").trigger("focus").trigger("select");
}; };
exports.quote_and_reply = function (opts) { exports.quote_and_reply = function (opts) {

View File

@@ -33,7 +33,7 @@ exports.smart_insert = function (textarea, syntax) {
syntax += " "; syntax += " ";
} }
textarea.focus(); textarea.trigger("focus");
// We prefer to use insertText, which supports things like undo better // We prefer to use insertText, which supports things like undo better
// for rich-text editing features like inserting links. But we fall // for rich-text editing features like inserting links. But we fall

View File

@@ -230,7 +230,7 @@ function handle_keydown(e) {
// takes the typeaheads a little time to open after the user finishes typing, which // takes the typeaheads a little time to open after the user finishes typing, which
// can lead to the focus moving without the autocomplete having a chance to happen. // can lead to the focus moving without the autocomplete having a chance to happen.
if (nextFocus) { if (nextFocus) {
$(nextFocus).focus(); $(nextFocus).trigger("focus");
nextFocus = false; nextFocus = false;
} }
@@ -254,7 +254,7 @@ function handle_keyup(e) {
if (code === 13 || (code === 9 && !e.shiftKey)) { if (code === 13 || (code === 9 && !e.shiftKey)) {
// Enter key or tab key // Enter key or tab key
if (nextFocus) { if (nextFocus) {
$(nextFocus).focus(); $(nextFocus).trigger("focus");
nextFocus = false; nextFocus = false;
} }
} }
@@ -272,7 +272,7 @@ function select_on_focus(field_id) {
} }
in_handler = true; in_handler = true;
$("#" + field_id) $("#" + field_id)
.select() .trigger("select")
.one("mouseup", (e) => { .one("mouseup", (e) => {
e.preventDefault(); e.preventDefault();
}); });
@@ -802,7 +802,7 @@ const show_flatpickr = (element, callback, default_timestamp) => {
instance.destroy(); instance.destroy();
}); });
instance.open(); instance.open();
container.find(".flatpickr-monthDropdown-months").focus(); container.find(".flatpickr-monthDropdown-months").trigger("focus");
}; };
exports.content_typeahead_selected = function (item, event) { exports.content_typeahead_selected = function (item, event) {
@@ -1077,7 +1077,7 @@ exports.initialize = function () {
// Refocus in the content box so you can continue typing or // Refocus in the content box so you can continue typing or
// press Enter to send. // press Enter to send.
$("#compose-textarea").focus(); $("#compose-textarea").trigger("focus");
return channel.post({ return channel.post({
url: "/json/users/me/enter-sends", url: "/json/users/me/enter-sends",

View File

@@ -378,7 +378,7 @@ exports.launch = function () {
function activate_element(elem) { function activate_element(elem) {
$(".draft-info-box").removeClass("active"); $(".draft-info-box").removeClass("active");
$(elem).expectOne().addClass("active"); $(elem).expectOne().addClass("active");
elem.focus(); elem.trigger("focus");
} }
function drafts_initialize_focus(event_name) { function drafts_initialize_focus(event_name) {

View File

@@ -97,7 +97,7 @@ const DropdownListWidget = function (opts) {
// On opening a Bootstrap Dropdown, the parent element recieves focus. // On opening a Bootstrap Dropdown, the parent element recieves focus.
// Here, we want our search input to have focus instead. // Here, we want our search input to have focus instead.
e.preventDefault(); e.preventDefault();
search_input.focus(); search_input.trigger("focus");
}); });
search_input.on("keydown", (e) => { search_input.on("keydown", (e) => {

View File

@@ -265,7 +265,7 @@ function process_enter_while_filtering(e) {
const first_emoji = get_rendered_emoji(0, 0); const first_emoji = get_rendered_emoji(0, 0);
if (first_emoji) { if (first_emoji) {
if (is_composition(first_emoji)) { if (is_composition(first_emoji)) {
first_emoji.click(); first_emoji.trigger("click");
} else { } else {
toggle_reaction(first_emoji.attr("data-emoji-name"), e); toggle_reaction(first_emoji.attr("data-emoji-name"), e);
} }
@@ -318,10 +318,10 @@ function maybe_change_focused_emoji($emoji_map, next_section, next_index, preser
current_section = next_section; current_section = next_section;
current_index = next_index; current_index = next_index;
if (!preserve_scroll) { if (!preserve_scroll) {
next_emoji.focus(); next_emoji.trigger("focus");
} else { } else {
const start = ui.get_scroll_element($emoji_map).scrollTop(); const start = ui.get_scroll_element($emoji_map).scrollTop();
next_emoji.focus(); next_emoji.trigger("focus");
if (ui.get_scroll_element($emoji_map).scrollTop() !== start) { if (ui.get_scroll_element($emoji_map).scrollTop() !== start) {
ui.get_scroll_element($emoji_map).scrollTop(start); ui.get_scroll_element($emoji_map).scrollTop(start);
} }
@@ -380,7 +380,7 @@ function get_next_emoji_coordinates(move_by) {
} }
function change_focus_to_filter() { function change_focus_to_filter() {
$(".emoji-popover-filter").focus(); $(".emoji-popover-filter").trigger("focus");
// If search is active reset current selected emoji to first emoji. // If search is active reset current selected emoji to first emoji.
if (search_is_active) { if (search_is_active) {
current_section = 0; current_section = 0;
@@ -407,7 +407,7 @@ exports.navigate = function (event_name, e) {
if (event_name === "enter") { if (event_name === "enter") {
if (is_composition(e.target)) { if (is_composition(e.target)) {
e.target.click(); e.target.trigger("click");
} else { } else {
toggle_selected_emoji(e); toggle_selected_emoji(e);
} }
@@ -426,7 +426,7 @@ exports.navigate = function (event_name, e) {
const filter_text = $(".emoji-popover-filter").val(); const filter_text = $(".emoji-popover-filter").val();
const is_cursor_at_end = $(".emoji-popover-filter").caret() === filter_text.length; const is_cursor_at_end = $(".emoji-popover-filter").caret() === filter_text.length;
if (event_name === "down_arrow" || (is_cursor_at_end && event_name === "right_arrow")) { if (event_name === "down_arrow" || (is_cursor_at_end && event_name === "right_arrow")) {
selected_emoji.focus(); selected_emoji.trigger("focus");
if (current_section === 0 && current_index < 6) { if (current_section === 0 && current_index < 6) {
ui.get_scroll_element($emoji_map).scrollTop(0); ui.get_scroll_element($emoji_map).scrollTop(0);
} }
@@ -434,7 +434,7 @@ exports.navigate = function (event_name, e) {
return true; return true;
} }
if (event_name === "tab") { if (event_name === "tab") {
selected_emoji.focus(); selected_emoji.trigger("focus");
update_emoji_showcase(selected_emoji); update_emoji_showcase(selected_emoji);
return true; return true;
} }
@@ -451,7 +451,7 @@ exports.navigate = function (event_name, e) {
// goes to beginning) with something reasonable and // goes to beginning) with something reasonable and
// consistent (cursor goes to the end of the filter // consistent (cursor goes to the end of the filter
// string). // string).
$(".emoji-popover-filter").focus().caret(Infinity); $(".emoji-popover-filter").trigger("focus").caret(Infinity);
ui.get_scroll_element($emoji_map).scrollTop(0); ui.get_scroll_element($emoji_map).scrollTop(0);
ui.get_scroll_element($(".emoji-search-results-container")).scrollTop(0); ui.get_scroll_element($(".emoji-search-results-container")).scrollTop(0);
current_section = 0; current_section = 0;
@@ -608,7 +608,7 @@ exports.render_emoji_popover = function (elt, id) {
elt.prop("title", i18n.t("Add emoji reaction (:)")); elt.prop("title", i18n.t("Add emoji reaction (:)"));
const popover = elt.data("popover").$tip; const popover = elt.data("popover").$tip;
popover.find(".emoji-popover-filter").focus(); popover.find(".emoji-popover-filter").trigger("focus");
current_message_emoji_popover_elem = elt; current_message_emoji_popover_elem = elt;
emoji_catalog_last_coordinates = { emoji_catalog_last_coordinates = {

View File

@@ -120,9 +120,9 @@ exports.initialize = function () {
}; };
exports.open = function () { exports.open = function () {
$("#settings-dropdown").click(); $("#settings-dropdown").trigger("click");
// there are invisible li tabs, which should not be clicked. // there are invisible li tabs, which should not be clicked.
$("#gear-menu").find("li:not(.invisible) a").eq(0).focus(); $("#gear-menu").find("li:not(.invisible) a").eq(0).trigger("focus");
}; };
exports.is_open = function () { exports.is_open = function () {

View File

@@ -231,10 +231,10 @@ exports.process_escape_key = function (e) {
} }
if ($("#searchbox").has(":focus")) { if ($("#searchbox").has(":focus")) {
$("input:focus,textarea:focus").blur(); $("input:focus,textarea:focus").trigger("blur");
if (page_params.search_pills_enabled) { if (page_params.search_pills_enabled) {
$("#searchbox .pill").blur(); $("#searchbox .pill").trigger("blur");
$("#searchbox #search_query").blur(); $("#searchbox #search_query").trigger("blur");
} else { } else {
tab_bar.exit_search(); tab_bar.exit_search();
} }
@@ -243,7 +243,7 @@ exports.process_escape_key = function (e) {
// We pressed Esc and something was focused, and the composebox // We pressed Esc and something was focused, and the composebox
// wasn't open. In that case, we should blur the input. // wasn't open. In that case, we should blur the input.
$("input:focus,textarea:focus").blur(); $("input:focus,textarea:focus").trigger("blur");
return true; return true;
} }
@@ -272,12 +272,12 @@ exports.process_enter_key = function (e) {
// on #gear-menu li a[tabindex] elements, force a click and prevent default. // on #gear-menu li a[tabindex] elements, force a click and prevent default.
// this is because these links do not have an href and so don't force a // this is because these links do not have an href and so don't force a
// default action. // default action.
e.target.click(); e.target.trigger("click");
return true; return true;
} }
if (hotspots.is_open()) { if (hotspots.is_open()) {
$(e.target).find(".hotspot.overlay.show .hotspot-confirm").click(); $(e.target).find(".hotspot.overlay.show .hotspot-confirm").trigger("click");
return false; return false;
} }
@@ -286,7 +286,7 @@ exports.process_enter_key = function (e) {
} }
if (exports.in_content_editable_widget(e)) { if (exports.in_content_editable_widget(e)) {
$(e.target).parent().find(".checkmark").click(); $(e.target).parent().find(".checkmark").trigger("click");
return false; return false;
} }
@@ -359,14 +359,14 @@ exports.process_tab_key = function () {
if (focused_message_edit_content.length > 0) { if (focused_message_edit_content.length > 0) {
message_edit_form = focused_message_edit_content.closest(".message_edit_form"); message_edit_form = focused_message_edit_content.closest(".message_edit_form");
// Open message edit forms either have a save button or a close button, but not both. // Open message edit forms either have a save button or a close button, but not both.
message_edit_form.find(".message_edit_save,.message_edit_close").focus(); message_edit_form.find(".message_edit_save,.message_edit_close").trigger("focus");
return true; return true;
} }
const focused_message_edit_save = $(".message_edit_save").filter(":focus"); const focused_message_edit_save = $(".message_edit_save").filter(":focus");
if (focused_message_edit_save.length > 0) { if (focused_message_edit_save.length > 0) {
message_edit_form = focused_message_edit_save.closest(".message_edit_form"); message_edit_form = focused_message_edit_save.closest(".message_edit_form");
message_edit_form.find(".message_edit_cancel").focus(); message_edit_form.find(".message_edit_cancel").trigger("focus");
return true; return true;
} }
@@ -391,7 +391,7 @@ exports.process_shift_tab_key = function () {
// Shift-tabbing from the edit message cancel button takes you to save. // Shift-tabbing from the edit message cancel button takes you to save.
if ($(".message_edit_cancel").filter(":focus").length > 0) { if ($(".message_edit_cancel").filter(":focus").length > 0) {
$(".message_edit_save").focus(); $(".message_edit_save").trigger("focus");
return true; return true;
} }
@@ -401,7 +401,7 @@ exports.process_shift_tab_key = function () {
focused_message_edit_save focused_message_edit_save
.closest(".message_edit_form") .closest(".message_edit_form")
.find(".message_edit_content") .find(".message_edit_content")
.focus(); .trigger("focus");
return true; return true;
} }

View File

@@ -14,7 +14,7 @@ exports.set_up_toggler = function () {
callback: function (name, key) { callback: function (name, key) {
$(".overlay-modal").hide(); $(".overlay-modal").hide();
$("#" + key).show(); $("#" + key).show();
ui.get_scroll_element($("#" + key).find(".modal-body")).focus(); ui.get_scroll_element($("#" + key).find(".modal-body")).trigger("focus");
}, },
}; };

View File

@@ -280,7 +280,7 @@ exports.create = function (opts) {
// below that handles events on the ".pill" class. // below that handles events on the ".pill" class.
if (char === KEY.LEFT_ARROW) { if (char === KEY.LEFT_ARROW) {
if (window.getSelection().anchorOffset === 0) { if (window.getSelection().anchorOffset === 0) {
store.$parent.find(".pill").last().focus(); store.$parent.find(".pill").last().trigger("focus");
} }
} }
@@ -306,14 +306,14 @@ exports.create = function (opts) {
const $pill = store.$parent.find(".pill:focus"); const $pill = store.$parent.find(".pill:focus");
if (char === KEY.LEFT_ARROW) { if (char === KEY.LEFT_ARROW) {
$pill.prev().focus(); $pill.prev().trigger("focus");
} else if (char === KEY.RIGHT_ARROW) { } else if (char === KEY.RIGHT_ARROW) {
$pill.next().focus(); $pill.next().trigger("focus");
} else if (char === KEY.BACKSPACE) { } else if (char === KEY.BACKSPACE) {
const $next = $pill.next(); const $next = $pill.next();
const id = $pill.data("id"); const id = $pill.data("id");
funcs.removePill(id); funcs.removePill(id);
$next.focus(); $next.trigger("focus");
// the "backspace" key in FireFox will go back a page if you do // the "backspace" key in FireFox will go back a page if you do
// not prevent it. // not prevent it.
e.preventDefault(); e.preventDefault();
@@ -351,12 +351,12 @@ exports.create = function (opts) {
const id = $pill.data("id"); const id = $pill.data("id");
funcs.removePill(id); funcs.removePill(id);
$next.focus(); $next.trigger("focus");
}); });
store.$parent.on("click", function (e) { store.$parent.on("click", function (e) {
if ($(e.target).is(".pill-container")) { if ($(e.target).is(".pill-container")) {
$(this).find(".input").focus(); $(this).find(".input").trigger("focus");
} }
}); });

View File

@@ -152,7 +152,7 @@ function prepare_form_to_be_shown() {
exports.launch = function () { exports.launch = function () {
$("#submit-invitation").button(); $("#submit-invitation").button();
prepare_form_to_be_shown(); prepare_form_to_be_shown();
autosize($("#invitee_emails").focus()); autosize($("#invitee_emails").trigger("focus"));
overlays.open_overlay({ overlays.open_overlay({
name: "invite", name: "invite",

View File

@@ -253,11 +253,11 @@ exports.parse_image_data = function (image) {
}; };
exports.prev = function () { exports.prev = function () {
$(".image-list .image.selected").prev().click(); $(".image-list .image.selected").prev().trigger("click");
}; };
exports.next = function () { exports.next = function () {
$(".image-list .image.selected").next().click(); $(".image-list .image.selected").next().trigger("click");
}; };
// this is a block of events that are required for the lightbox to work. // this is a block of events that are required for the lightbox to work.
@@ -332,7 +332,7 @@ exports.initialize = function () {
}); });
$("#lightbox_overlay .image-preview").on("dblclick", "img, canvas", (e) => { $("#lightbox_overlay .image-preview").on("dblclick", "img, canvas", (e) => {
$("#lightbox_overlay .lightbox-canvas-trigger").click(); $("#lightbox_overlay .lightbox-canvas-trigger").trigger("click");
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -33,7 +33,7 @@ const list_cursor = function (opts) {
// TODO: The list class should probably do more of the work // TODO: The list class should probably do more of the work
// here, so we're not so coupled to jQuery, and // here, so we're not so coupled to jQuery, and
// so we instead just get back a widget we can say // so we instead just get back a widget we can say
// something like widget.select() on. This will // something like widget.trigger("select") on. This will
// be especially important if we do lazy rendering. // be especially important if we do lazy rendering.
// It would also give the caller more flexibility on // It would also give the caller more flexibility on
// the actual styling. // the actual styling.

View File

@@ -8,12 +8,12 @@ exports.inside_list = function (e) {
exports.go_down = function (e) { exports.go_down = function (e) {
const $target = $(e.target); const $target = $(e.target);
$target.closest("li").next().find("a").focus(); $target.closest("li").next().find("a").trigger("focus");
}; };
exports.go_up = function (e) { exports.go_up = function (e) {
const $target = $(e.target); const $target = $(e.target);
$target.closest("li").prev().find("a").focus(); $target.closest("li").prev().find("a").trigger("focus");
}; };
window.list_util = exports; window.list_util = exports;

View File

@@ -162,7 +162,7 @@ exports.show_topic_edit_spinner = function (row) {
exports.end_if_focused_on_inline_topic_edit = function () { exports.end_if_focused_on_inline_topic_edit = function () {
const focused_elem = $(".topic_edit_form").find(":focus"); const focused_elem = $(".topic_edit_form").find(":focus");
if (focused_elem.length === 1) { if (focused_elem.length === 1) {
focused_elem.blur(); focused_elem.trigger("blur");
const recipient_row = focused_elem.closest(".recipient_row"); const recipient_row = focused_elem.closest(".recipient_row");
exports.end_inline_topic_edit(recipient_row); exports.end_inline_topic_edit(recipient_row);
} }
@@ -171,7 +171,7 @@ exports.end_if_focused_on_inline_topic_edit = function () {
exports.end_if_focused_on_message_row_edit = function () { exports.end_if_focused_on_message_row_edit = function () {
const focused_elem = $(".message_edit").find(":focus"); const focused_elem = $(".message_edit").find(":focus");
if (focused_elem.length === 1) { if (focused_elem.length === 1) {
focused_elem.blur(); focused_elem.trigger("blur");
const row = focused_elem.closest(".message_row"); const row = focused_elem.closest(".message_row");
exports.end_message_row_edit(row); exports.end_message_row_edit(row);
} }
@@ -425,14 +425,14 @@ function edit_message(row, raw_content) {
} }
if (!is_editable) { if (!is_editable) {
row.find(".message_edit_close").focus(); row.find(".message_edit_close").trigger("focus");
} else if (message.type === "stream" && message.topic === compose.empty_topic_placeholder()) { } else if (message.type === "stream" && message.topic === compose.empty_topic_placeholder()) {
message_edit_topic.val(""); message_edit_topic.val("");
message_edit_topic.focus(); message_edit_topic.trigger("focus");
} else if (editability === editability_types.TOPIC_ONLY) { } else if (editability === editability_types.TOPIC_ONLY) {
row.find(".message_edit_topic").focus(); row.find(".message_edit_topic").trigger("focus");
} else { } else {
message_edit_content.focus(); message_edit_content.trigger("focus");
// Put cursor at end of input. // Put cursor at end of input.
const contents = message_edit_content.val(); const contents = message_edit_content.val();
message_edit_content.val(""); message_edit_content.val("");
@@ -525,7 +525,7 @@ exports.start_topic_edit = function (recipient_row) {
if (topic === compose.empty_topic_placeholder()) { if (topic === compose.empty_topic_placeholder()) {
topic = ""; topic = "";
} }
form.find(".inline_topic_edit").val(topic).select().focus(); form.find(".inline_topic_edit").val(topic).trigger("select").trigger("focus");
}; };
exports.is_editing = function (id) { exports.is_editing = function (id) {
@@ -561,7 +561,7 @@ exports.end_message_row_edit = function (row) {
// We have to blur out text fields, or else hotkeys.js // We have to blur out text fields, or else hotkeys.js
// thinks we are still editing. // thinks we are still editing.
row.find(".message_edit").blur(); row.find(".message_edit").trigger("blur");
}; };
exports.save_inline_topic_edit = function (row) { exports.save_inline_topic_edit = function (row) {
@@ -812,7 +812,7 @@ exports.edit_last_sent_message = function () {
// Finally do the real work! // Finally do the real work!
compose_actions.cancel(); compose_actions.cancel();
exports.start(msg_row, () => { exports.start(msg_row, () => {
$("#message_edit_content").focus(); $("#message_edit_content").trigger("focus");
}); });
}; };

View File

@@ -411,7 +411,7 @@ function process_notification(notification) {
if (message.type !== "test-notification") { if (message.type !== "test-notification") {
narrow.by_topic(message.id, {trigger: "notification"}); narrow.by_topic(message.id, {trigger: "notification"});
} }
window.focus(); window.trigger("focus");
}); });
notification_object.addEventListener("close", () => { notification_object.addEventListener("close", () => {
notice_memory.delete(key); notice_memory.delete(key);

View File

@@ -222,7 +222,7 @@ exports.activate = function (opts) {
const question = poll_data.get_question(); const question = poll_data.get_question();
elem.find("input.poll-question").val(question); elem.find("input.poll-question").val(question);
render_question(); render_question();
elem.find("input.poll-question").focus(); elem.find("input.poll-question").trigger("focus");
} }
function abort_edit() { function abort_edit() {
@@ -268,7 +268,7 @@ exports.activate = function (opts) {
return; return;
} }
poll_option_input.val("").focus(); poll_option_input.val("").trigger("focus");
const data = poll_data.handle.new_option.outbound(option); const data = poll_data.handle.new_option.outbound(option);
callback(data); callback(data);

View File

@@ -562,7 +562,7 @@ function focus_first_popover_item(items) {
return; return;
} }
items.eq(0).expectOne().focus(); items.eq(0).expectOne().trigger("focus");
} }
function popover_items_handle_keyboard(key, items) { function popover_items_handle_keyboard(key, items) {
@@ -573,7 +573,7 @@ function popover_items_handle_keyboard(key, items) {
let index = items.index(items.filter(":focus")); let index = items.index(items.filter(":focus"));
if (key === "enter" && index >= 0 && index < items.length) { if (key === "enter" && index >= 0 && index < items.length) {
return items[index].click(); return items[index].trigger("click");
} }
if (index === -1) { if (index === -1) {
index = 0; index = 0;
@@ -582,7 +582,7 @@ function popover_items_handle_keyboard(key, items) {
} else if ((key === "up_arrow" || key === "vim_up") && index > 0) { } else if ((key === "up_arrow" || key === "vim_up") && index > 0) {
index -= 1; index -= 1;
} }
items.eq(index).focus(); items.eq(index).trigger("focus");
} }
function focus_first_action_popover_item() { function focus_first_action_popover_item() {
@@ -1035,7 +1035,7 @@ exports.register_click_handlers = function () {
exports.hide_actions_popover(); exports.hide_actions_popover();
message_edit_history.show_history(message); message_edit_history.show_history(message);
message_history_cancel_btn.focus(); message_history_cancel_btn.trigger("focus");
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}); });
@@ -1083,7 +1083,7 @@ exports.register_click_handlers = function () {
setTimeout(() => { setTimeout(() => {
// The Cliboard library works by focusing to a hidden textarea. // The Cliboard library works by focusing to a hidden textarea.
// We unfocus this so keyboard shortcuts, etc., will work again. // We unfocus this so keyboard shortcuts, etc., will work again.
$(":focus").blur(); $(":focus").trigger("blur");
}, 0); }, 0);
e.stopPropagation(); e.stopPropagation();

View File

@@ -1,3 +1,3 @@
$(() => { $(() => {
$("#register").submit(); $("#register").trigger("submit");
}); });

View File

@@ -1,6 +1,6 @@
$(() => { $(() => {
$(".portico-header li.logout").on("click", () => { $(".portico-header li.logout").on("click", () => {
$("#logout_form").submit(); $("#logout_form").trigger("submit");
return false; return false;
}); });

View File

@@ -330,7 +330,7 @@ function integration_events() {
const integration = $(integrations[i]).find(".integration-lozenge"); const integration = $(integrations[i]).find(".integration-lozenge");
if ($(integration).css("display") !== "none") { if ($(integration).css("display") !== "none") {
$(integration).closest("a")[0].click(); $(integration).closest("a")[0].trigger("click");
break; break;
} }
} }
@@ -370,7 +370,7 @@ function integration_events() {
// combine selector use for both focusing the integrations searchbar and adding // combine selector use for both focusing the integrations searchbar and adding
// the input event. // the input event.
$(".integrations .searchbar input[type='text']") $(".integrations .searchbar input[type='text']")
.focus() .trigger("focus")
.on("input", (e) => { .on("input", (e) => {
dispatch("UPDATE_QUERY", {query: e.target.value.toLowerCase()}); dispatch("UPDATE_QUERY", {query: e.target.value.toLowerCase()});
}); });

View File

@@ -82,7 +82,7 @@ $(() => {
// endpoint is visited i.e. accounts_send_confirm.html is rendered. // endpoint is visited i.e. accounts_send_confirm.html is rendered.
if ($("[data-page-id='accounts-send-confirm']").length > 0) { if ($("[data-page-id='accounts-send-confirm']").length > 0) {
$("#resend_email_link").on("click", () => { $("#resend_email_link").on("click", () => {
$(".resend_confirm").submit(); $(".resend_confirm").trigger("submit");
}); });
} }

View File

@@ -34,7 +34,7 @@ function set_default_focus() {
// If at any point we are confused about the currently // If at any point we are confused about the currently
// focused element, we switch focus to search. // focused element, we switch focus to search.
current_focus_elem = $("#recent_topics_search"); current_focus_elem = $("#recent_topics_search");
current_focus_elem.focus(); current_focus_elem.trigger("focus");
} }
function set_table_focus(row, col) { function set_table_focus(row, col) {
@@ -46,7 +46,7 @@ function set_table_focus(row, col) {
return true; return true;
} }
topic_rows.eq(row).find(".recent_topics_focusable").eq(col).children().focus(); topic_rows.eq(row).find(".recent_topics_focusable").eq(col).children().trigger("focus");
current_focus_elem = "table"; current_focus_elem = "table";
return true; return true;
} }
@@ -72,7 +72,7 @@ function revive_current_focus() {
current_focus_elem = $("#recent_topics_filter_buttons").find( current_focus_elem = $("#recent_topics_filter_buttons").find(
"[data-filter='" + filter_button + "']", "[data-filter='" + filter_button + "']",
); );
current_focus_elem.focus(); current_focus_elem.trigger("focus");
} }
return true; return true;
} }
@@ -505,7 +505,7 @@ exports.change_focused_element = function (e, input_key) {
return true; return true;
case "click": case "click":
// Note: current_focus_elem can be different here, so we just // Note: current_focus_elem can be different here, so we just
// set current_focus_elem to the input box, we don't want .focus() on // set current_focus_elem to the input box, we don't want .trigger("focus") on
// it since it is already focused. // it since it is already focused.
// We only do this for search beacuse we don't want the focus to // We only do this for search beacuse we don't want the focus to
// go away from the input box when `revive_current_focus` is called // go away from the input box when `revive_current_focus` is called
@@ -560,7 +560,7 @@ exports.change_focused_element = function (e, input_key) {
return true; return true;
} }
if (current_focus_elem) { if (current_focus_elem) {
current_focus_elem.focus(); current_focus_elem.trigger("focus");
} }
return true; return true;

View File

@@ -32,7 +32,7 @@ exports.narrow_or_search_for_term = function (search_string) {
// Narrowing will have already put some operators in the search box, // Narrowing will have already put some operators in the search box,
// so leave the current text in. // so leave the current text in.
if (!page_params.search_pills_enabled) { if (!page_params.search_pills_enabled) {
search_query_box.blur(); search_query_box.trigger("blur");
} }
return search_query_box.val(); return search_query_box.val();
}; };
@@ -147,7 +147,7 @@ exports.initialize = function () {
// Pill is already added during keydown event of input pills. // Pill is already added during keydown event of input pills.
exports.narrow_or_search_for_term(search_query_box.val()); exports.narrow_or_search_for_term(search_query_box.val());
search_query_box.blur(); search_query_box.trigger("blur");
update_buttons_with_focus(false); update_buttons_with_focus(false);
} }
}); });
@@ -211,14 +211,14 @@ exports.initiate_search = function () {
$("#searchbox").css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"}); $("#searchbox").css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
$("#search_query").typeahead("lookup").select(); $("#search_query").typeahead("lookup").select();
if (page_params.search_pills_enabled) { if (page_params.search_pills_enabled) {
$("#search_query").focus(); $("#search_query").trigger("focus");
ui_util.place_caret_at_end($("#search_query")[0]); ui_util.place_caret_at_end($("#search_query")[0]);
} }
}; };
exports.clear_search_form = function () { exports.clear_search_form = function () {
$("#search_query").val(""); $("#search_query").val("");
$("#search_query").blur(); $("#search_query").trigger("blur");
$(".search_button").prop("disabled", true); $(".search_button").prop("disabled", true);
}; };

View File

@@ -865,7 +865,7 @@ exports.build_page = function () {
$(e.target) $(e.target)
.closest(".org-subsection-parent") .closest(".org-subsection-parent")
.find(".subsection-changes-save button") .find(".subsection-changes-save button")
.click(); .trigger("click");
} }
}); });

View File

@@ -22,7 +22,7 @@ exports.make_menu = function (opts) {
// In one colum mode want to show the settings list, not the first settings section. // In one colum mode want to show the settings list, not the first settings section.
self.activate_section_or_default(section); self.activate_section_or_default(section);
} }
curr_li.focus(); curr_li.trigger("focus");
}; };
self.hide = function () { self.hide = function () {
@@ -52,12 +52,12 @@ exports.make_menu = function (opts) {
}; };
self.prev = function () { self.prev = function () {
curr_li.prevAll(":visible:first").focus().click(); curr_li.prevAll(":visible:first").trigger("focus").trigger("click");
return true; return true;
}; };
self.next = function () { self.next = function () {
curr_li.nextAll(":visible:first").focus().click(); curr_li.nextAll(":visible:first").trigger("focus").trigger("click");
return true; return true;
}; };
@@ -66,7 +66,7 @@ exports.make_menu = function (opts) {
const sel = "input:visible,button:visible,select:visible"; const sel = "input:visible,button:visible,select:visible";
const panel_elem = panel.find(sel).first(); const panel_elem = panel.find(sel).first();
panel_elem.focus(); panel_elem.trigger("focus");
return true; return true;
}; };

View File

@@ -272,7 +272,7 @@ exports.populate_user_groups = function () {
// the DOM. // the DOM.
update_cancel_button(); update_cancel_button();
setTimeout(() => { setTimeout(() => {
input.focus(); input.trigger("focus");
}, 100); }, 100);
}); });
})(); })();

View File

@@ -60,7 +60,7 @@ const stream_name_error = (function () {
}; };
self.select = function () { self.select = function () {
$("#create_stream_name").focus().select(); $("#create_stream_name").trigger("focus").trigger("select");
}; };
self.pre_validate = function (stream_name) { self.pre_validate = function (stream_name) {
@@ -227,7 +227,7 @@ function create_stream() {
// error text directly rather than turning it into // error text directly rather than turning it into
// "Error creating stream"? // "Error creating stream"?
stream_name_error.report_already_exists(stream_name); stream_name_error.report_already_exists(stream_name);
stream_name_error.select(); stream_name_error.trigger("select");
} }
ui_report.error(i18n.t("Error creating stream"), xhr, $(".stream_create_info")); ui_report.error(i18n.t("Error creating stream"), xhr, $(".stream_create_info"));
@@ -260,7 +260,7 @@ exports.new_stream_clicked = function (stream_name) {
// is clear is that this shouldn't be touched unless you're also changing // is clear is that this shouldn't be touched unless you're also changing
// the mobile @media query at 700px. // the mobile @media query at 700px.
if (window.innerWidth > 700) { if (window.innerWidth > 700) {
$("#create_stream_name").focus(); $("#create_stream_name").trigger("focus");
} }
}; };

View File

@@ -569,7 +569,7 @@ exports.clear_search = function (e) {
return; return;
} }
filter.val(""); filter.val("");
filter.blur(); filter.trigger("blur");
update_streams_for_search(); update_streams_for_search();
}; };
@@ -592,7 +592,7 @@ exports.initiate_search = function () {
popovers.hide_all(); popovers.hide_all();
stream_popover.show_streamlist_sidebar(); stream_popover.show_streamlist_sidebar();
} }
filter.focus(); filter.trigger("focus");
exports.stream_cursor.reset(); exports.stream_cursor.reset();
}; };
@@ -604,7 +604,7 @@ exports.clear_and_hide_search = function () {
update_streams_for_search(); update_streams_for_search();
} }
exports.stream_cursor.clear(); exports.stream_cursor.clear();
filter.blur(); filter.trigger("blur");
exports.hide_search_section(); exports.hide_search_section();
}; };

View File

@@ -241,7 +241,7 @@ exports.add_sub_to_table = function (sub) {
// good way to associate with this request because the stream // good way to associate with this request because the stream
// ID isn't known yet. These are appended to the top of the // ID isn't known yet. These are appended to the top of the
// list, so they are more visible. // list, so they are more visible.
exports.row_for_stream_id(sub.stream_id).click(); exports.row_for_stream_id(sub.stream_id).trigger("click");
stream_create.reset_created_stream(); stream_create.reset_created_stream();
} }
}; };
@@ -653,7 +653,7 @@ exports.switch_to_stream_row = function (stream_id) {
// It's dubious that we need this timeout any more. // It's dubious that we need this timeout any more.
setTimeout(() => { setTimeout(() => {
if (stream_id === exports.get_active_data().id) { if (stream_id === exports.get_active_data().id) {
stream_row.click(); stream_row.trigger("click");
} }
}, 100); }, 100);
}; };
@@ -709,7 +709,7 @@ exports.launch = function (section) {
exports.change_state(section); exports.change_state(section);
}); });
if (!exports.get_active_data().id) { if (!exports.get_active_data().id) {
$("#search_stream_name").focus(); $("#search_stream_name").trigger("focus");
} }
}; };
@@ -722,7 +722,7 @@ exports.switch_rows = function (event) {
} else if (!active_data.id || active_data.row.hasClass("notdisplayed")) { } else if (!active_data.id || active_data.row.hasClass("notdisplayed")) {
switch_row = $("div.stream-row:not(.notdisplayed)").first(); switch_row = $("div.stream-row:not(.notdisplayed)").first();
if ($("#search_stream_name").is(":focus")) { if ($("#search_stream_name").is(":focus")) {
$("#search_stream_name").blur(); $("#search_stream_name").trigger("blur");
} }
} else { } else {
if (event === "up_arrow") { if (event === "up_arrow") {
@@ -733,7 +733,7 @@ exports.switch_rows = function (event) {
if ($("#search_stream_name").is(":focus")) { if ($("#search_stream_name").is(":focus")) {
// remove focus from Filter streams input instead of switching rows // remove focus from Filter streams input instead of switching rows
// if Filter streams input is focused // if Filter streams input is focused
return $("#search_stream_name").blur(); return $("#search_stream_name").trigger("blur");
} }
} }
@@ -742,7 +742,7 @@ exports.switch_rows = function (event) {
const stream_id = row_data.id; const stream_id = row_data.id;
exports.switch_to_stream_row(stream_id); exports.switch_to_stream_row(stream_id);
} else if (event === "up_arrow" && !row_data) { } else if (event === "up_arrow" && !row_data) {
$("#search_stream_name").focus(); $("#search_stream_name").trigger("focus");
} }
return true; return true;
}; };

View File

@@ -143,8 +143,8 @@ exports.activate = function (opts) {
return; return;
} }
elem.find(".add-task").val("").focus(); elem.find(".add-task").val("").trigger("focus");
elem.find(".add-desc").val("").focus(); elem.find(".add-desc").val("").trigger("focus");
const task_exists = task_data.name_in_use(task); const task_exists = task_data.name_in_use(task);
if (task_exists) { if (task_exists) {

View File

@@ -178,7 +178,7 @@ exports.maybe_show_deprecation_notice = function (key) {
if (!shown_deprecation_notices.includes(key)) { if (!shown_deprecation_notices.includes(key)) {
$("#deprecation-notice-modal").modal("show"); $("#deprecation-notice-modal").modal("show");
$("#deprecation-notice-message").text(message); $("#deprecation-notice-message").text(message);
$("#close-deprecation-notice").focus(); $("#close-deprecation-notice").trigger("focus");
shown_deprecation_notices.push(key); shown_deprecation_notices.push(key);
if (localstorage.supported()) { if (localstorage.supported()) {
localStorage.setItem( localStorage.setItem(
@@ -206,7 +206,7 @@ exports.set_compose_textarea_handlers = function () {
}; };
exports.restore_compose_cursor = function () { exports.restore_compose_cursor = function () {
$("#compose-textarea").focus().caret(saved_compose_cursor); $("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
}; };
exports.initialize = function () { exports.initialize = function () {

View File

@@ -7,7 +7,7 @@ exports.change_tab_to = function (tabname) {
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser // https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
exports.place_caret_at_end = function (el) { exports.place_caret_at_end = function (el) {
el.focus(); el.trigger("focus");
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") { if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
const range = document.createRange(); const range = document.createRange();

View File

@@ -127,7 +127,7 @@ exports.upload_files = function (uppy, config, files) {
}); });
compose_ui.autosize_textarea(); compose_ui.autosize_textarea();
uppy.cancelAll(); uppy.cancelAll();
exports.get_item("textarea", config).focus(); exports.get_item("textarea", config).trigger("focus");
setTimeout(() => { setTimeout(() => {
exports.hide_upload_status(config); exports.hide_upload_status(config);
}, 500); }, 500);

View File

@@ -145,7 +145,7 @@ exports.set_up_typeahead_on_pills = function (input, pills, update_func, source)
}, },
updater: function (user) { updater: function (user) {
exports.append_user(user, pills); exports.append_user(user, pills);
input.focus(); input.trigger("focus");
update_func(); update_func();
}, },
stopAdvance: true, stopAdvance: true,

View File

@@ -31,7 +31,7 @@ const user_search = function (opts) {
} }
$input.val(""); $input.val("");
$input.blur(); $input.trigger("blur");
opts.reset_items(); opts.reset_items();
}; };
@@ -71,7 +71,7 @@ const user_search = function (opts) {
}; };
self.close_widget = function () { self.close_widget = function () {
$input.blur(); $input.trigger("blur");
self.hide_widget(); self.hide_widget();
opts.reset_items(); opts.reset_items();
}; };
@@ -91,7 +91,7 @@ const user_search = function (opts) {
self.initiate_search = function () { self.initiate_search = function () {
self.expand_column(); self.expand_column();
self.show_widget(); self.show_widget();
$input.focus(); $input.trigger("focus");
}; };
self.toggle_filter_displayed = function () { self.toggle_filter_displayed = function () {

View File

@@ -18,8 +18,8 @@ exports.open_overlay = function () {
const old_status_text = user_status.get_status_text(user_id); const old_status_text = user_status.get_status_text(user_id);
const field = exports.input_field(); const field = exports.input_field();
field.val(old_status_text); field.val(old_status_text);
field.select(); field.trigger("select");
field.focus(); field.trigger("focus");
exports.toggle_clear_message_button(); exports.toggle_clear_message_button();
const button = exports.submit_button(); const button = exports.submit_button();