Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Replace deprecated jQuery event trigger shorthand.

Anders Kaseorga9ca5f603b7f
diff --git a/frontend_tests/casper_lib/common.js b/frontend_tests/casper_lib/common.js
index 87dd064c956..96129f9787f 100644
--- a/frontend_tests/casper_lib/common.js
+++ b/frontend_tests/casper_lib/common.js
@@ -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
// the typeahead.
$(field_selector)
- .focus()
+ .trigger("focus")
.val(str)
.trigger($.Event("keyup", {which: 0}));
diff --git a/frontend_tests/casper_tests/03-narrow.js b/frontend_tests/casper_tests/03-narrow.js
index 0201e864363..87c90bed9ca 100644
--- a/frontend_tests/casper_tests/03-narrow.js
+++ b/frontend_tests/casper_tests/03-narrow.js
@@ -345,7 +345,7 @@ casper.waitWhileSelector("#streams_list .input-append.notdisplayed", function ()
// Enter the search box and test highlighted suggestion navigation
casper.then(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 () {
$(".stream-list-filter")
.expectOne()
- .focus()
+ .trigger("focus")
.val("sCoT")
.trigger($.Event("input"))
.trigger($.Event("click"));
@@ -436,7 +436,7 @@ casper.then(function () {
// Clearing the list should give us back all the streams in the list
casper.then(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
casper.then(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
casper.then(function () {
casper.evaluate(function () {
- $("#user_filter_icon").expectOne().focus().trigger($.Event("click"));
+ $("#user_filter_icon").expectOne().trigger("focus").trigger($.Event("click"));
});
});
diff --git a/frontend_tests/casper_tests/07-stars.js b/frontend_tests/casper_tests/07-stars.js
index c19067f4418..79e05f474bf 100644
--- a/frontend_tests/casper_tests/07-stars.js
+++ b/frontend_tests/casper_tests/07-stars.js
@@ -20,7 +20,7 @@ function toggle_test_star_message() {
return "cannot find star icon";
}
- star_icon.click();
+ star_icon.trigger("click");
});
if (error) {
diff --git a/frontend_tests/casper_tests/08-edit.js b/frontend_tests/casper_tests/08-edit.js
index bc85149013c..700ec1bf608 100644
--- a/frontend_tests/casper_tests/08-edit.js
+++ b/frontend_tests/casper_tests/08-edit.js
@@ -9,8 +9,8 @@ function then_edit_last_message() {
casper.then(function () {
casper.evaluate(function () {
var msg = $("#zhome .message_row").last();
- msg.find(".info").click();
- $(".popover_edit_message").click();
+ msg.find(".info").trigger("click");
+ $(".popover_edit_message").trigger("click");
});
});
casper.then(function () {
@@ -33,7 +33,7 @@ casper.then(function () {
var msg = $("#zhome .message_row").last();
msg.find(".message_edit_topic").val("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();
msg.find(".message_edit_topic").val("edited");
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 () {
var msg = $("#zhome .message_row").last();
msg.find(".message_edit_content").val("test edited pm");
- msg.find(".message_edit_save").click();
+ msg.find(".message_edit_save").trigger("click");
});
});
diff --git a/frontend_tests/casper_tests/10-admin.js b/frontend_tests/casper_tests/10-admin.js
index 3fc3da12d52..b1dec0d6145 100644
--- a/frontend_tests/casper_tests/10-admin.js
+++ b/frontend_tests/casper_tests/10-admin.js
@@ -302,7 +302,7 @@ function get_suggestions(str) {
casper.then(function () {
casper.evaluate(function (str) {
$(".create_default_stream")
- .focus()
+ .trigger("focus")
.val(str)
.trigger($.Event("keyup", {which: 0}));
}, str);
diff --git a/frontend_tests/casper_tests/15-delete-message.js b/frontend_tests/casper_tests/15-delete-message.js
index 7d26d37830f..10814cf8ba3 100644
--- a/frontend_tests/casper_tests/15-delete-message.js
+++ b/frontend_tests/casper_tests/15-delete-message.js
@@ -15,8 +15,8 @@ casper.then(function () {
});
last_message_id = this.evaluate(function () {
var msg = $("#zhome .message_row").last();
- msg.find(".info").click();
- $(".delete_message").click();
+ msg.find(".info").trigger("click");
+ $(".delete_message").trigger("click");
return msg.attr("id");
});
});
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index dd086358174..80e927851cf 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -243,7 +243,7 @@ function reset_setup() {
reset_setup();
run_test("presence_list_full_update", () => {
- $(".user-list-filter").focus();
+ $(".user-list-filter").trigger("focus");
compose_state.private_message_recipient = () => fred.email;
compose_fade.set_focused_recipient("private");
@@ -603,7 +603,7 @@ run_test("escape_search", () => {
reset_setup();
run_test("initiate_search", () => {
- $(".user-list-filter").blur();
+ $(".user-list-filter").trigger("blur");
simulate_right_column_buddy_list();
activity.initiate_search();
assert.equal($(".column-right").hasClass("expanded"), true);
@@ -627,9 +627,9 @@ run_test("toggle_filter_display", () => {
});
run_test("searching", () => {
- $(".user-list-filter").focus();
+ $(".user-list-filter").trigger("focus");
assert.equal(activity.searching(), true);
- $(".user-list-filter").blur();
+ $(".user-list-filter").trigger("blur");
assert.equal(activity.searching(), false);
});
diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js
index 9f181eb3484..24fb9ea3b45 100644
--- a/frontend_tests/node_tests/common.js
+++ b/frontend_tests/node_tests/common.js
@@ -11,7 +11,7 @@ $("body").append = noop;
$(input).val = (arg) => {
assert.equal(arg, "[email protected]");
return {
- select: noop,
+ trigger: noop,
};
};
diff --git a/frontend_tests/node_tests/components.js b/frontend_tests/node_tests/components.js
index e9221fc2ee7..9fb28df60e2 100644
--- a/frontend_tests/node_tests/components.js
+++ b/frontend_tests/node_tests/components.js
@@ -42,8 +42,10 @@ run_test("basics", () => {
return i;
};
- self.focus = function () {
- focused_tab = i;
+ self.trigger = function (type) {
+ if (type === "focus") {
+ focused_tab = i;
+ }
};
tabs.push(self);
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js
index e2336e2d526..f91a5f03a23 100644
--- a/frontend_tests/node_tests/compose.js
+++ b/frontend_tests/node_tests/compose.js
@@ -196,7 +196,7 @@ run_test("validate", () => {
set_global("$", global.make_zjquery());
$("#compose-send-button").prop("disabled", false);
- $("#compose-send-button").focus();
+ $("#compose-send-button").trigger("focus");
$("#sending-indicator").hide();
const pm_pill_container = $.create("fake-pm-pill-container");
@@ -588,7 +588,7 @@ run_test("markdown_shortcuts", () => {
run_test("send_message_success", () => {
$("#compose-textarea").val("foobarfoobar");
- $("#compose-textarea").blur();
+ $("#compose-textarea").trigger("blur");
$("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show();
@@ -686,7 +686,7 @@ run_test("send_message", () => {
// Setting message content with a host server link and we will assert
// later that this has been converted to a relative link.
$("#compose-textarea").val("[foobar]" + "(https://foo.com/user_uploads/123456)");
- $("#compose-textarea").blur();
+ $("#compose-textarea").trigger("blur");
$("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show();
@@ -738,7 +738,7 @@ run_test("send_message", () => {
(function test_error_codepath_local_id_undefined() {
stub_state = initialize_state_stub_dict();
$("#compose-textarea").val("foobarfoobar");
- $("#compose-textarea").blur();
+ $("#compose-textarea").trigger("blur");
$("#compose-send-status").show();
$("#compose-send-button").attr("disabled", "disabled");
$("#sending-indicator").show();
@@ -794,7 +794,7 @@ run_test("enter_with_preview_open", () => {
assert(send_message_called);
page_params.enter_sends = false;
- $("#compose-textarea").blur();
+ $("#compose-textarea").trigger("blur");
compose.enter_with_preview_open();
assert($("#compose-textarea").is_focused());
@@ -814,7 +814,7 @@ run_test("finish", () => {
(function test_when_compose_validation_fails() {
$("#compose_invite_users").show();
$("#compose-send-button").prop("disabled", false);
- $("#compose-send-button").focus();
+ $("#compose-send-button").trigger("focus");
$("#sending-indicator").hide();
$("#compose-textarea").off("select");
$("#compose-textarea").val("");
diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js
index 9aa618b551b..b52181eb5ab 100644
--- a/frontend_tests/node_tests/compose_actions.js
+++ b/frontend_tests/node_tests/compose_actions.js
@@ -409,7 +409,7 @@ run_test("focus_in_empty_compose", () => {
compose_state.composing = return_true;
$("#compose-textarea").val("");
- $("#compose-textarea").focus();
+ $("#compose-textarea").trigger("focus");
assert(compose_state.focus_in_empty_compose());
compose_state.composing = return_false;
@@ -418,7 +418,7 @@ run_test("focus_in_empty_compose", () => {
$("#compose-textarea").val("foo");
assert(!compose_state.focus_in_empty_compose());
- $("#compose-textarea").blur();
+ $("#compose-textarea").trigger("blur");
assert(!compose_state.focus_in_empty_compose());
});
diff --git a/frontend_tests/node_tests/compose_ui.js b/frontend_tests/node_tests/compose_ui.js
index 9ad7ac9cb31..b13dbd16065 100644
--- a/frontend_tests/node_tests/compose_ui.js
+++ b/frontend_tests/node_tests/compose_ui.js
@@ -50,14 +50,6 @@ function make_textbox(s) {
return widget.pos;
};
- widget.focus = function () {
- widget.focused = true;
- };
-
- widget.blur = function () {
- widget.focused = false;
- };
-
widget.val = function (new_val) {
if (new_val) {
widget.s = new_val;
@@ -66,8 +58,12 @@ function make_textbox(s) {
}
};
- widget.trigger = function () {
- return;
+ widget.trigger = function (type) {
+ if (type === "focus") {
+ widget.focused = true;
+ } else if (type === "blur") {
+ widget.focused = false;
+ }
};
return widget;
@@ -98,21 +94,21 @@ run_test("smart_insert", () => {
assert.equal(textbox.val(), "abc :smile: ");
assert(textbox.focused);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":airplane:");
assert.equal(textbox.insert_text, ":airplane: ");
assert.equal(textbox.val(), "abc :smile: :airplane: ");
assert(textbox.focused);
textbox.caret(0);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":octopus:");
assert.equal(textbox.insert_text, ":octopus: ");
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: ");
assert(textbox.focused);
textbox.caret(textbox.val().length);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, ":heart:");
assert.equal(textbox.insert_text, ":heart: ");
assert.equal(textbox.val(), ":octopus: abc :smile: :airplane: :heart: ");
@@ -121,7 +117,7 @@ run_test("smart_insert", () => {
// Test handling of spaces for ```quote
textbox = make_textbox("");
textbox.caret(0);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, "```quote\nquoted message\n```\n");
assert.equal(textbox.insert_text, "```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.caret(0);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, "[Quoting…]\n");
assert.equal(textbox.insert_text, "[Quoting…]\n");
assert.equal(textbox.val(), "[Quoting…]\n");
@@ -137,7 +133,7 @@ run_test("smart_insert", () => {
textbox = make_textbox("abc");
textbox.caret(3);
- textbox.blur();
+ textbox.trigger("blur");
compose_ui.smart_insert(textbox, " test with space");
assert.equal(textbox.insert_text, " test with space ");
assert.equal(textbox.val(), "abc test with space ");
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js
index e2286b7ed8a..68730653664 100644
--- a/frontend_tests/node_tests/composebox_typeahead.js
+++ b/frontend_tests/node_tests/composebox_typeahead.js
@@ -777,7 +777,7 @@ run_test("initialize", () => {
const click_event = {type: "click", target: "#doesnotmatter"};
options.query = "othello";
// 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);
assert.equal(appended_name, "Othello, the Moor of Venice");
@@ -969,6 +969,7 @@ run_test("initialize", () => {
// handle_keydown()
let event = {
+ type: "keydown",
keyCode: 13,
target: {
id: "stream_message_recipient_stream",
@@ -979,7 +980,7 @@ run_test("initialize", () => {
$("#stream_message_recipient_topic").data = function () {
return {typeahead: {shown: true}};
};
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
const stub_typeahead_hidden = function () {
return {typeahead: {shown: false}};
@@ -988,17 +989,17 @@ run_test("initialize", () => {
$("#stream_message_recipient_stream").data = stub_typeahead_hidden;
$("#private_message_recipient").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.which = 9;
event.shiftKey = false;
event.target.id = "subject";
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
event.target.id = "compose-textarea";
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
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
// handler.
@@ -1015,7 +1016,7 @@ run_test("initialize", () => {
event.keyCode = 13;
event.target.id = "stream_message_recipient_topic";
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
event.target.id = "compose-textarea";
page_params.enter_sends = false;
event.metaKey = true;
@@ -1024,50 +1025,52 @@ run_test("initialize", () => {
compose_finish_called = true;
};
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
assert(compose_finish_called);
event.metaKey = false;
event.ctrlKey = true;
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
page_params.enter_sends = true;
event.ctrlKey = false;
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.
range_length = 2;
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
event.altKey = false;
event.metaKey = true;
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
event.target.id = "private_message_recipient";
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
event.keyCode = 42;
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
// handle_keyup()
event = {
+ type: "keydown",
keyCode: 13,
target: {
id: "stream_message_recipient_stream",
},
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 () {
return {typeahead: {shown: true}};
};
- $("form#send_message_form").keydown(event);
+ $("form#send_message_form").trigger(event);
$("#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.which = 9;
event.shiftKey = false;
- $("form#send_message_form").keyup(event);
+ $("form#send_message_form").trigger(event);
event.keyCode = 42;
- $("form#send_message_form").keyup(event);
+ $("form#send_message_form").trigger(event);
// select_on_focus()
@@ -1084,14 +1087,14 @@ run_test("initialize", () => {
$("#enter_sends").is = function () {
return false;
};
- $("#enter_sends").click();
+ $("#enter_sends").trigger("click");
// Now we re-run both .initialize() and the click handler, this time
// with enter_sends: page_params.enter_sends being true
$("#enter_sends").is = function () {
return true;
};
- $("#enter_sends").click();
+ $("#enter_sends").trigger("click");
$("#stream_message_recipient_stream").off("focus");
$("#stream_message_recipient_topic").off("focus");
diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js
index 72124bc6d81..0cf495bbdb1 100644
--- a/frontend_tests/node_tests/input_pill.js
+++ b/frontend_tests/node_tests/input_pill.js
@@ -236,13 +236,17 @@ run_test("arrows on pills", () => {
const pill_stub = {
prev: () => ({
- focus: () => {
- prev_focused = true;
+ trigger: (type) => {
+ if (type === "focus") {
+ prev_focused = true;
+ }
},
}),
next: () => ({
- focus: () => {
- next_focused = true;
+ trigger: (type) => {
+ if (type === "focus") {
+ next_focused = true;
+ }
},
}),
};
@@ -274,8 +278,10 @@ run_test("left arrow on input", () => {
container.set_find_results(".pill", {
last: () => ({
- focus: () => {
- last_pill_focused = true;
+ trigger: (type) => {
+ if (type === "focus") {
+ last_pill_focused = true;
+ }
},
}),
});
@@ -411,8 +417,10 @@ run_test("insert_remove", () => {
let next_pill_focused = false;
const next_pill_stub = {
- focus: () => {
- next_pill_focused = true;
+ trigger: (type) => {
+ if (type === "focus") {
+ next_pill_focused = true;
+ }
},
};
@@ -449,8 +457,10 @@ run_test("exit button on pill", () => {
let next_pill_focused = false;
const next_pill_stub = {
- focus: () => {
- next_pill_focused = true;
+ trigger: (type) => {
+ if (type === "focus") {
+ next_pill_focused = true;
+ }
},
};
diff --git a/frontend_tests/node_tests/keydown_util.js b/frontend_tests/node_tests/keydown_util.js
index 677dfd7b800..221753b04d7 100644
--- a/frontend_tests/node_tests/keydown_util.js
+++ b/frontend_tests/node_tests/keydown_util.js
@@ -14,24 +14,26 @@ run_test("test_early_returns", () => {
};
keydown_util.handle(opts);
- const keydown_f = stub.keydown;
const e1 = {
+ type: "keydown",
which: 17, // not in keys
};
- keydown_f(e1);
+ stub.trigger(e1);
const e2 = {
+ type: "keydown",
which: 13, // no handler
};
- keydown_f(e2);
+ stub.trigger(e2);
const e3 = {
+ type: "keydown",
which: 37,
altKey: true, // let browser handle
};
- keydown_f(e3);
+ stub.trigger(e3);
});
diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js
index bbfcc478c45..a82404803ab 100644
--- a/frontend_tests/node_tests/search.js
+++ b/frontend_tests/node_tests/search.js
@@ -31,7 +31,7 @@ global.patch_builtin("setTimeout", (func) => func());
run_test("clear_search_form", () => {
$("#search_query").val("noise");
- $("#search_query").focus();
+ $("#search_query").trigger("focus");
$(".search_button").prop("disabled", false);
search.clear_search_form();
diff --git a/frontend_tests/node_tests/settings_bots.js b/frontend_tests/node_tests/settings_bots.js
index 51798394275..6ac37602e42 100644
--- a/frontend_tests/node_tests/settings_bots.js
+++ b/frontend_tests/node_tests/settings_bots.js
@@ -140,11 +140,7 @@ run_test("test tab clicks", () => {
set_up();
function click_on_tab(tab_elem) {
- const e = {
- preventDefault: () => {},
- stopPropagation: () => {},
- };
- tab_elem.click(e);
+ tab_elem.trigger("click");
}
const tabs = {
diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js
index ef791e40faf..9a0243ef7a9 100644
--- a/frontend_tests/node_tests/zjquery.js
+++ b/frontend_tests/node_tests/zjquery.js
@@ -131,11 +131,11 @@ run_test("clicks", () => {
assert(!state.keydown);
// But we can simulate clicks.
- $("#widget1").click();
+ $("#widget1").trigger("click");
assert.equal(state.clicked, true);
// and keydown
- $(".some-class").keydown();
+ $(".some-class").trigger("keydown");
assert.equal(state.keydown, true);
});
diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js
index f2f53b9a0a3..c21e8bb216e 100644
--- a/static/js/alert_words_ui.js
+++ b/static/js/alert_words_ui.js
@@ -15,7 +15,7 @@ exports.render_alert_words_ui = function () {
}
// 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) {
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 8ce7415f832..28e7a6c3d75 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -9,7 +9,7 @@ function convert_enter_to_click(e) {
const key = e.which;
if (key === 13) {
// enter
- $(e.currentTarget).click();
+ $(e.currentTarget).trigger("click");
}
}
@@ -200,7 +200,7 @@ exports.initialize = function () {
if (page_params.realm_allow_edit_history) {
message_edit_history.show_history(message);
- message_history_cancel_btn.focus();
+ message_history_cancel_btn.trigger("focus");
}
e.stopPropagation();
e.preventDefault();
@@ -601,7 +601,7 @@ exports.initialize = function () {
notifications.register_click_handlers();
$("body").on("click", ".logout_button", () => {
- $("#logout_form").submit();
+ $("#logout_form").trigger("submit");
});
$(".restart_get_events_button").on("click", () => {
@@ -757,24 +757,24 @@ exports.initialize = function () {
// disable the draggability for left-sidebar components
$("#stream_filters, #global_filters").on("dragstart", (e) => {
- e.target.blur();
+ e.target.trigger("blur");
return false;
});
// Chrome focuses an element when dragging it which can be confusing when
// 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.
$("body").on("mouseup", "a", (e) => {
if (e.which === 2) {
// middle click
- e.target.blur();
+ e.target.trigger("blur");
}
});
// 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 () {
const map = {
@@ -797,7 +797,7 @@ exports.initialize = function () {
$(this).text($(this).attr("data-prev-text"));
$("[data-make-editable]").html("");
} 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 ($(e.target).closest("a").length > 0) {
// Refocus compose message text box if link is clicked
- $("#compose-textarea").focus();
+ $("#compose-textarea").trigger("focus");
return;
} else if (
!window.getSelection().toString() &&
diff --git a/static/js/common.js b/static/js/common.js
index bdb8bc1de1a..65a18c38129 100644
--- a/static/js/common.js
+++ b/static/js/common.js
@@ -7,7 +7,7 @@ exports.status_classes = "alert-error alert-success alert-info alert-warning";
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
const temp = $(document.createElement("input"));
$("body").append(temp);
- temp.val(elem.data(key)).select();
+ temp.val(elem.data(key)).trigger("select");
document.execCommand("copy");
temp.remove();
elem.fadeOut(250);
diff --git a/static/js/components.js b/static/js/components.js
index 70d33473fd8..a973c01e6cd 100644
--- a/static/js/components.js
+++ b/static/js/components.js
@@ -65,7 +65,7 @@ exports.toggle = function (opts) {
}
if (!opts.child_wants_focus) {
- elem.focus();
+ elem.trigger("focus");
}
}
diff --git a/static/js/compose.js b/static/js/compose.js
index 6359eb688e9..a6622569269 100644
--- a/static/js/compose.js
+++ b/static/js/compose.js
@@ -259,7 +259,7 @@ function compose_error(error_text, bad_input) {
$("#compose-send-button").prop("disabled", false);
$("#sending-indicator").hide();
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();
$(".compose-send-status-close").hide();
if (bad_input !== undefined) {
- bad_input.focus().select();
+ bad_input.trigger("focus").trigger("select");
}
}
exports.nonexistent_stream_reply_error = nonexistent_stream_reply_error;
function clear_compose_box() {
- $("#compose-textarea").val("").focus();
+ $("#compose-textarea").val("").trigger("focus");
drafts.delete_draft_after_send();
compose_ui.autosize_textarea();
$("#compose-send-status").hide(0);
@@ -379,7 +379,7 @@ exports.enter_with_preview_open = function () {
exports.finish();
} else {
// 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 () {
- $("#compose-send-button").attr("disabled", "disabled").blur();
+ $("#compose-send-button").attr("disabled", "disabled").trigger("blur");
const message_content = compose_state.message_content();
if (reminder.is_deferred_delivery(message_content)) {
show_sending_indicator(i18n.t("Scheduling..."));
diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js
index 19b3a80d55b..7d1d9b06c3c 100644
--- a/static/js/compose_actions.js
+++ b/static/js/compose_actions.js
@@ -1,7 +1,7 @@
const autosize = require("autosize");
exports.blur_textarea = function () {
- $(".message_comp").find("input, textarea, button").blur();
+ $(".message_comp").find("input, textarea, button").trigger("blur");
};
function hide_box() {
@@ -45,7 +45,7 @@ exports.set_focus = function (msg_type, opts) {
if (window.getSelection().toString() === "" || opts.trigger !== "message click") {
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_fade.set_focused_recipient("stream");
compose_fade.update_message_list();
- $("#compose-textarea").focus().select();
+ $("#compose-textarea").trigger("focus").trigger("select");
};
exports.quote_and_reply = function (opts) {
diff --git a/static/js/compose_ui.js b/static/js/compose_ui.js
index 9fa35f8da19..ac1784d4f4f 100644
--- a/static/js/compose_ui.js
+++ b/static/js/compose_ui.js
@@ -33,7 +33,7 @@ exports.smart_insert = function (textarea, syntax) {
syntax += " ";
}
- textarea.focus();
+ textarea.trigger("focus");
// We prefer to use insertText, which supports things like undo better
// for rich-text editing features like inserting links. But we fall
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 7616f797893..19a7ae0a9df 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -230,7 +230,7 @@ function handle_keydown(e) {
// 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.
if (nextFocus) {
- $(nextFocus).focus();
+ $(nextFocus).trigger("focus");
nextFocus = false;
}
@@ -254,7 +254,7 @@ function handle_keyup(e) {
if (code === 13 || (code === 9 && !e.shiftKey)) {
// Enter key or tab key
if (nextFocus) {
- $(nextFocus).focus();
+ $(nextFocus).trigger("focus");
nextFocus = false;
}
}
@@ -272,7 +272,7 @@ function select_on_focus(field_id) {
}
in_handler = true;
$("#" + field_id)
- .select()
+ .trigger("select")
.one("mouseup", (e) => {
e.preventDefault();
});
@@ -802,7 +802,7 @@ const show_flatpickr = (element, callback, default_timestamp) => {
instance.destroy();
});
instance.open();
- container.find(".flatpickr-monthDropdown-months").focus();
+ container.find(".flatpickr-monthDropdown-months").trigger("focus");
};
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
// press Enter to send.
- $("#compose-textarea").focus();
+ $("#compose-textarea").trigger("focus");
return channel.post({
url: "/json/users/me/enter-sends",
diff --git a/static/js/drafts.js b/static/js/drafts.js
index 1cc7dc96ffe..ead9c7bb651 100644
--- a/static/js/drafts.js
+++ b/static/js/drafts.js
@@ -378,7 +378,7 @@ exports.launch = function () {
function activate_element(elem) {
$(".draft-info-box").removeClass("active");
$(elem).expectOne().addClass("active");
- elem.focus();
+ elem.trigger("focus");
}
function drafts_initialize_focus(event_name) {
diff --git a/static/js/dropdown_list_widget.js b/static/js/dropdown_list_widget.js
index 6e0382ae25f..ff9f5dd0f34 100644
--- a/static/js/dropdown_list_widget.js
+++ b/static/js/dropdown_list_widget.js
@@ -97,7 +97,7 @@ const DropdownListWidget = function (opts) {
// On opening a Bootstrap Dropdown, the parent element recieves focus.
// Here, we want our search input to have focus instead.
e.preventDefault();
- search_input.focus();
+ search_input.trigger("focus");
});
search_input.on("keydown", (e) => {
diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js
index 32d3f665510..3b757a5dd43 100644
--- a/static/js/emoji_picker.js
+++ b/static/js/emoji_picker.js
@@ -265,7 +265,7 @@ function process_enter_while_filtering(e) {
const first_emoji = get_rendered_emoji(0, 0);
if (first_emoji) {
if (is_composition(first_emoji)) {
- first_emoji.click();
+ first_emoji.trigger("click");
} else {
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_index = next_index;
if (!preserve_scroll) {
- next_emoji.focus();
+ next_emoji.trigger("focus");
} else {
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) {
ui.get_scroll_element($emoji_map).scrollTop(start);
}
@@ -380,7 +380,7 @@ function get_next_emoji_coordinates(move_by) {
}
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) {
current_section = 0;
@@ -407,7 +407,7 @@ exports.navigate = function (event_name, e) {
if (event_name === "enter") {
if (is_composition(e.target)) {
- e.target.click();
+ e.target.trigger("click");
} else {
toggle_selected_emoji(e);
}
@@ -426,7 +426,7 @@ exports.navigate = function (event_name, e) {
const filter_text = $(".emoji-popover-filter").val();
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")) {
- selected_emoji.focus();
+ selected_emoji.trigger("focus");
if (current_section === 0 && current_index < 6) {
ui.get_scroll_element($emoji_map).scrollTop(0);
}
@@ -434,7 +434,7 @@ exports.navigate = function (event_name, e) {
return true;
}
if (event_name === "tab") {
- selected_emoji.focus();
+ selected_emoji.trigger("focus");
update_emoji_showcase(selected_emoji);
return true;
}
@@ -451,7 +451,7 @@ exports.navigate = function (event_name, e) {
// goes to beginning) with something reasonable and
// consistent (cursor goes to the end of the filter
// 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-search-results-container")).scrollTop(0);
current_section = 0;
@@ -608,7 +608,7 @@ exports.render_emoji_popover = function (elt, id) {
elt.prop("title", i18n.t("Add emoji reaction (:)"));
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;
emoji_catalog_last_coordinates = {
diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js
index b4f51ca7f82..a0c168db129 100644
--- a/static/js/gear_menu.js
+++ b/static/js/gear_menu.js
@@ -120,9 +120,9 @@ exports.initialize = function () {
};
exports.open = function () {
- $("#settings-dropdown").click();
+ $("#settings-dropdown").trigger("click");
// 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 () {
diff --git a/static/js/hotkey.js b/static/js/hotkey.js
index d0c1c328ef9..29cc1046462 100644
--- a/static/js/hotkey.js
+++ b/static/js/hotkey.js
@@ -231,10 +231,10 @@ exports.process_escape_key = function (e) {
}
if ($("#searchbox").has(":focus")) {
- $("input:focus,textarea:focus").blur();
+ $("input:focus,textarea:focus").trigger("blur");
if (page_params.search_pills_enabled) {
- $("#searchbox .pill").blur();
- $("#searchbox #search_query").blur();
+ $("#searchbox .pill").trigger("blur");
+ $("#searchbox #search_query").trigger("blur");
} else {
tab_bar.exit_search();
}
@@ -243,7 +243,7 @@ exports.process_escape_key = function (e) {
// We pressed Esc and something was focused, and the composebox
// wasn't open. In that case, we should blur the input.
- $("input:focus,textarea:focus").blur();
+ $("input:focus,textarea:focus").trigger("blur");
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.
// this is because these links do not have an href and so don't force a
// default action.
- e.target.click();
+ e.target.trigger("click");
return true;
}
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;
}
@@ -286,7 +286,7 @@ exports.process_enter_key = function (e) {
}
if (exports.in_content_editable_widget(e)) {
- $(e.target).parent().find(".checkmark").click();
+ $(e.target).parent().find(".checkmark").trigger("click");
return false;
}
@@ -359,14 +359,14 @@ exports.process_tab_key = function () {
if (focused_message_edit_content.length > 0) {
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.
- 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;
}
const focused_message_edit_save = $(".message_edit_save").filter(":focus");
if (focused_message_edit_save.length > 0) {
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;
}
@@ -391,7 +391,7 @@ exports.process_shift_tab_key = function () {
// Shift-tabbing from the edit message cancel button takes you to save.
if ($(".message_edit_cancel").filter(":focus").length > 0) {
- $(".message_edit_save").focus();
+ $(".message_edit_save").trigger("focus");
return true;
}
@@ -401,7 +401,7 @@ exports.process_shift_tab_key = function () {
focused_message_edit_save
.closest(".message_edit_form")
.find(".message_edit_content")
- .focus();
+ .trigger("focus");
return true;
}
diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js
index ad796ca8e04..15e597cacee 100644
--- a/static/js/info_overlay.js
+++ b/static/js/info_overlay.js
@@ -14,7 +14,7 @@ exports.set_up_toggler = function () {
callback: function (name, key) {
$(".overlay-modal").hide();
$("#" + key).show();
- ui.get_scroll_element($("#" + key).find(".modal-body")).focus();
+ ui.get_scroll_element($("#" + key).find(".modal-body")).trigger("focus");
},
};
diff --git a/static/js/input_pill.js b/static/js/input_pill.js
index 44a6b9ac458..bfb27dff3db 100644
--- a/static/js/input_pill.js
+++ b/static/js/input_pill.js
@@ -280,7 +280,7 @@ exports.create = function (opts) {
// below that handles events on the ".pill" class.
if (char === KEY.LEFT_ARROW) {
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");
if (char === KEY.LEFT_ARROW) {
- $pill.prev().focus();
+ $pill.prev().trigger("focus");
} else if (char === KEY.RIGHT_ARROW) {
- $pill.next().focus();
+ $pill.next().trigger("focus");
} else if (char === KEY.BACKSPACE) {
const $next = $pill.next();
const id = $pill.data("id");
funcs.removePill(id);
- $next.focus();
+ $next.trigger("focus");
// the "backspace" key in FireFox will go back a page if you do
// not prevent it.
e.preventDefault();
@@ -351,12 +351,12 @@ exports.create = function (opts) {
const id = $pill.data("id");
funcs.removePill(id);
- $next.focus();
+ $next.trigger("focus");
});
store.$parent.on("click", function (e) {
if ($(e.target).is(".pill-container")) {
- $(this).find(".input").focus();
+ $(this).find(".input").trigger("focus");
}
});
diff --git a/static/js/invite.js b/static/js/invite.js
index cf69f82169a..e33dd62260a 100644
--- a/static/js/invite.js
+++ b/static/js/invite.js
@@ -152,7 +152,7 @@ function prepare_form_to_be_shown() {
exports.launch = function () {
$("#submit-invitation").button();
prepare_form_to_be_shown();
- autosize($("#invitee_emails").focus());
+ autosize($("#invitee_emails").trigger("focus"));
overlays.open_overlay({
name: "invite",
diff --git a/static/js/lightbox.js b/static/js/lightbox.js
index d1e2c8e5bc5..404ff21890a 100644
--- a/static/js/lightbox.js
+++ b/static/js/lightbox.js
@@ -253,11 +253,11 @@ exports.parse_image_data = function (image) {
};
exports.prev = function () {
- $(".image-list .image.selected").prev().click();
+ $(".image-list .image.selected").prev().trigger("click");
};
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.
@@ -332,7 +332,7 @@ exports.initialize = function () {
});
$("#lightbox_overlay .image-preview").on("dblclick", "img, canvas", (e) => {
- $("#lightbox_overlay .lightbox-canvas-trigger").click();
+ $("#lightbox_overlay .lightbox-canvas-trigger").trigger("click");
e.preventDefault();
});
diff --git a/static/js/list_cursor.js b/static/js/list_cursor.js
index 9df3e4e19fc..ffc4c0ac934 100644
--- a/static/js/list_cursor.js
+++ b/static/js/list_cursor.js
@@ -33,7 +33,7 @@ const list_cursor = function (opts) {
// TODO: The list class should probably do more of the work
// here, so we're not so coupled to jQuery, and
// 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.
// It would also give the caller more flexibility on
// the actual styling.
diff --git a/static/js/list_util.js b/static/js/list_util.js
index f8bec155345..5aeefeba568 100644
--- a/static/js/list_util.js
+++ b/static/js/list_util.js
@@ -8,12 +8,12 @@ exports.inside_list = function (e) {
exports.go_down = function (e) {
const $target = $(e.target);
- $target.closest("li").next().find("a").focus();
+ $target.closest("li").next().find("a").trigger("focus");
};
exports.go_up = function (e) {
const $target = $(e.target);
- $target.closest("li").prev().find("a").focus();
+ $target.closest("li").prev().find("a").trigger("focus");
};
window.list_util = exports;
diff --git a/static/js/message_edit.js b/static/js/message_edit.js
index 2d5ef2f822d..dfac99fc079 100644
--- a/static/js/message_edit.js
+++ b/static/js/message_edit.js
@@ -162,7 +162,7 @@ exports.show_topic_edit_spinner = function (row) {
exports.end_if_focused_on_inline_topic_edit = function () {
const focused_elem = $(".topic_edit_form").find(":focus");
if (focused_elem.length === 1) {
- focused_elem.blur();
+ focused_elem.trigger("blur");
const recipient_row = focused_elem.closest(".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 () {
const focused_elem = $(".message_edit").find(":focus");
if (focused_elem.length === 1) {
- focused_elem.blur();
+ focused_elem.trigger("blur");
const row = focused_elem.closest(".message_row");
exports.end_message_row_edit(row);
}
@@ -425,14 +425,14 @@ function edit_message(row, raw_content) {
}
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()) {
message_edit_topic.val("");
- message_edit_topic.focus();
+ message_edit_topic.trigger("focus");
} else if (editability === editability_types.TOPIC_ONLY) {
- row.find(".message_edit_topic").focus();
+ row.find(".message_edit_topic").trigger("focus");
} else {
- message_edit_content.focus();
+ message_edit_content.trigger("focus");
// Put cursor at end of input.
const contents = 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()) {
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) {
@@ -561,7 +561,7 @@ exports.end_message_row_edit = function (row) {
// We have to blur out text fields, or else hotkeys.js
// thinks we are still editing.
- row.find(".message_edit").blur();
+ row.find(".message_edit").trigger("blur");
};
exports.save_inline_topic_edit = function (row) {
@@ -812,7 +812,7 @@ exports.edit_last_sent_message = function () {
// Finally do the real work!
compose_actions.cancel();
exports.start(msg_row, () => {
- $("#message_edit_content").focus();
+ $("#message_edit_content").trigger("focus");
});
};
diff --git a/static/js/notifications.js b/static/js/notifications.js
index 89403b5fe7b..1dc02cf8b9e 100644
--- a/static/js/notifications.js
+++ b/static/js/notifications.js
@@ -411,7 +411,7 @@ function process_notification(notification) {
if (message.type !== "test-notification") {
narrow.by_topic(message.id, {trigger: "notification"});
}
- window.focus();
+ window.trigger("focus");
});
notification_object.addEventListener("close", () => {
notice_memory.delete(key);
diff --git a/static/js/poll_widget.js b/static/js/poll_widget.js
index 4491c59dd26..0d1df62342b 100644
--- a/static/js/poll_widget.js
+++ b/static/js/poll_widget.js
@@ -222,7 +222,7 @@ exports.activate = function (opts) {
const question = poll_data.get_question();
elem.find("input.poll-question").val(question);
render_question();
- elem.find("input.poll-question").focus();
+ elem.find("input.poll-question").trigger("focus");
}
function abort_edit() {
@@ -268,7 +268,7 @@ exports.activate = function (opts) {
return;
}
- poll_option_input.val("").focus();
+ poll_option_input.val("").trigger("focus");
const data = poll_data.handle.new_option.outbound(option);
callback(data);
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 3d1625bfbe7..0c85df8b137 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -562,7 +562,7 @@ function focus_first_popover_item(items) {
return;
}
- items.eq(0).expectOne().focus();
+ items.eq(0).expectOne().trigger("focus");
}
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"));
if (key === "enter" && index >= 0 && index < items.length) {
- return items[index].click();
+ return items[index].trigger("click");
}
if (index === -1) {
index = 0;
@@ -582,7 +582,7 @@ function popover_items_handle_keyboard(key, items) {
} else if ((key === "up_arrow" || key === "vim_up") && index > 0) {
index -= 1;
}
- items.eq(index).focus();
+ items.eq(index).trigger("focus");
}
function focus_first_action_popover_item() {
@@ -1035,7 +1035,7 @@ exports.register_click_handlers = function () {
exports.hide_actions_popover();
message_edit_history.show_history(message);
- message_history_cancel_btn.focus();
+ message_history_cancel_btn.trigger("focus");
e.stopPropagation();
e.preventDefault();
});
@@ -1083,7 +1083,7 @@ exports.register_click_handlers = function () {
setTimeout(() => {
// The Cliboard library works by focusing to a hidden textarea.
// We unfocus this so keyboard shortcuts, etc., will work again.
- $(":focus").blur();
+ $(":focus").trigger("blur");
}, 0);
e.stopPropagation();
diff --git a/static/js/portico/confirm-preregistrationuser.js b/static/js/portico/confirm-preregistrationuser.js
index 0de3aa36fad..10d2f883ffb 100644
--- a/static/js/portico/confirm-preregistrationuser.js
+++ b/static/js/portico/confirm-preregistrationuser.js
@@ -1,3 +1,3 @@
$(() => {
- $("#register").submit();
+ $("#register").trigger("submit");
});
diff --git a/static/js/portico/header.js b/static/js/portico/header.js
index 910150ded01..4043020b89f 100644
--- a/static/js/portico/header.js
+++ b/static/js/portico/header.js
@@ -1,6 +1,6 @@
$(() => {
$(".portico-header li.logout").on("click", () => {
- $("#logout_form").submit();
+ $("#logout_form").trigger("submit");
return false;
});
diff --git a/static/js/portico/integrations.js b/static/js/portico/integrations.js
index c7c74221b4c..0b051250eea 100644
--- a/static/js/portico/integrations.js
+++ b/static/js/portico/integrations.js
@@ -330,7 +330,7 @@ function integration_events() {
const integration = $(integrations[i]).find(".integration-lozenge");
if ($(integration).css("display") !== "none") {
- $(integration).closest("a")[0].click();
+ $(integration).closest("a")[0].trigger("click");
break;
}
}
@@ -370,7 +370,7 @@ function integration_events() {
// combine selector use for both focusing the integrations searchbar and adding
// the input event.
$(".integrations .searchbar input[type='text']")
- .focus()
+ .trigger("focus")
.on("input", (e) => {
dispatch("UPDATE_QUERY", {query: e.target.value.toLowerCase()});
});
diff --git a/static/js/portico/signup.js b/static/js/portico/signup.js
index 7d45239eca2..4bb166f851b 100644
--- a/static/js/portico/signup.js
+++ b/static/js/portico/signup.js
@@ -82,7 +82,7 @@ $(() => {
// endpoint is visited i.e. accounts_send_confirm.html is rendered.
if ($("[data-page-id='accounts-send-confirm']").length > 0) {
$("#resend_email_link").on("click", () => {
- $(".resend_confirm").submit();
+ $(".resend_confirm").trigger("submit");
});
}
diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js
index 710ff00b761..22d6f9f3024 100644
--- a/static/js/recent_topics.js
+++ b/static/js/recent_topics.js
@@ -34,7 +34,7 @@ function set_default_focus() {
// If at any point we are confused about the currently
// focused element, we switch focus to search.
current_focus_elem = $("#recent_topics_search");
- current_focus_elem.focus();
+ current_focus_elem.trigger("focus");
}
function set_table_focus(row, col) {
@@ -46,7 +46,7 @@ function set_table_focus(row, col) {
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";
return true;
}
@@ -72,7 +72,7 @@ function revive_current_focus() {
current_focus_elem = $("#recent_topics_filter_buttons").find(
"[data-filter='" + filter_button + "']",
);
- current_focus_elem.focus();
+ current_focus_elem.trigger("focus");
}
return true;
}
@@ -505,7 +505,7 @@ exports.change_focused_element = function (e, input_key) {
return true;
case "click":
// 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.
// 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
@@ -560,7 +560,7 @@ exports.change_focused_element = function (e, input_key) {
return true;
}
if (current_focus_elem) {
- current_focus_elem.focus();
+ current_focus_elem.trigger("focus");
}
return true;
diff --git a/static/js/search.js b/static/js/search.js
index 001021b85bc..46d5ee254ca 100644
--- a/static/js/search.js
+++ b/static/js/search.js
@@ -32,7 +32,7 @@ exports.narrow_or_search_for_term = function (search_string) {
// Narrowing will have already put some operators in the search box,
// so leave the current text in.
if (!page_params.search_pills_enabled) {
- search_query_box.blur();
+ search_query_box.trigger("blur");
}
return search_query_box.val();
};
@@ -147,7 +147,7 @@ exports.initialize = function () {
// Pill is already added during keydown event of input pills.
exports.narrow_or_search_for_term(search_query_box.val());
- search_query_box.blur();
+ search_query_box.trigger("blur");
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%)"});
$("#search_query").typeahead("lookup").select();
if (page_params.search_pills_enabled) {
- $("#search_query").focus();
+ $("#search_query").trigger("focus");
ui_util.place_caret_at_end($("#search_query")[0]);
}
};
exports.clear_search_form = function () {
$("#search_query").val("");
- $("#search_query").blur();
+ $("#search_query").trigger("blur");
$(".search_button").prop("disabled", true);
};
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index ceb8808168f..7f30840a590 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -865,7 +865,7 @@ exports.build_page = function () {
$(e.target)
.closest(".org-subsection-parent")
.find(".subsection-changes-save button")
- .click();
+ .trigger("click");
}
});
diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js
index e9f09a958e8..d6ebcf0a151 100644
--- a/static/js/settings_panel_menu.js
+++ b/static/js/settings_panel_menu.js
@@ -22,7 +22,7 @@ exports.make_menu = function (opts) {
// In one colum mode want to show the settings list, not the first settings section.
self.activate_section_or_default(section);
}
- curr_li.focus();
+ curr_li.trigger("focus");
};
self.hide = function () {
@@ -52,12 +52,12 @@ exports.make_menu = function (opts) {
};
self.prev = function () {
- curr_li.prevAll(":visible:first").focus().click();
+ curr_li.prevAll(":visible:first").trigger("focus").trigger("click");
return true;
};
self.next = function () {
- curr_li.nextAll(":visible:first").focus().click();
+ curr_li.nextAll(":visible:first").trigger("focus").trigger("click");
return true;
};
@@ -66,7 +66,7 @@ exports.make_menu = function (opts) {
const sel = "input:visible,button:visible,select:visible";
const panel_elem = panel.find(sel).first();
- panel_elem.focus();
+ panel_elem.trigger("focus");
return true;
};
diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js
index 7ce34e67243..f0325d037b2 100644
--- a/static/js/settings_user_groups.js
+++ b/static/js/settings_user_groups.js
@@ -272,7 +272,7 @@ exports.populate_user_groups = function () {
// the DOM.
update_cancel_button();
setTimeout(() => {
- input.focus();
+ input.trigger("focus");
}, 100);
});
})();
diff --git a/static/js/stream_create.js b/static/js/stream_create.js
index 0949e0c8409..f13f38e47fd 100644
--- a/static/js/stream_create.js
+++ b/static/js/stream_create.js
@@ -60,7 +60,7 @@ const stream_name_error = (function () {
};
self.select = function () {
- $("#create_stream_name").focus().select();
+ $("#create_stream_name").trigger("focus").trigger("select");
};
self.pre_validate = function (stream_name) {
@@ -227,7 +227,7 @@ function create_stream() {
// error text directly rather than turning it into
// "Error creating stream"?
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"));
@@ -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
// the mobile @media query at 700px.
if (window.innerWidth > 700) {
- $("#create_stream_name").focus();
+ $("#create_stream_name").trigger("focus");
}
};
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index 52cf435b234..5830aaada32 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -569,7 +569,7 @@ exports.clear_search = function (e) {
return;
}
filter.val("");
- filter.blur();
+ filter.trigger("blur");
update_streams_for_search();
};
@@ -592,7 +592,7 @@ exports.initiate_search = function () {
popovers.hide_all();
stream_popover.show_streamlist_sidebar();
}
- filter.focus();
+ filter.trigger("focus");
exports.stream_cursor.reset();
};
@@ -604,7 +604,7 @@ exports.clear_and_hide_search = function () {
update_streams_for_search();
}
exports.stream_cursor.clear();
- filter.blur();
+ filter.trigger("blur");
exports.hide_search_section();
};
diff --git a/static/js/subs.js b/static/js/subs.js
index 5dbb3735bba..42a875be02d 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -241,7 +241,7 @@ exports.add_sub_to_table = function (sub) {
// good way to associate with this request because the stream
// ID isn't known yet. These are appended to the top of the
// 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();
}
};
@@ -653,7 +653,7 @@ exports.switch_to_stream_row = function (stream_id) {
// It's dubious that we need this timeout any more.
setTimeout(() => {
if (stream_id === exports.get_active_data().id) {
- stream_row.click();
+ stream_row.trigger("click");
}
}, 100);
};
@@ -709,7 +709,7 @@ exports.launch = function (section) {
exports.change_state(section);
});
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")) {
switch_row = $("div.stream-row:not(.notdisplayed)").first();
if ($("#search_stream_name").is(":focus")) {
- $("#search_stream_name").blur();
+ $("#search_stream_name").trigger("blur");
}
} else {
if (event === "up_arrow") {
@@ -733,7 +733,7 @@ exports.switch_rows = function (event) {
if ($("#search_stream_name").is(":focus")) {
// remove focus from Filter streams input instead of switching rows
// 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;
exports.switch_to_stream_row(stream_id);
} else if (event === "up_arrow" && !row_data) {
- $("#search_stream_name").focus();
+ $("#search_stream_name").trigger("focus");
}
return true;
};
diff --git a/static/js/todo_widget.js b/static/js/todo_widget.js
index 7e51db3fde8..b4349b52a69 100644
--- a/static/js/todo_widget.js
+++ b/static/js/todo_widget.js
@@ -143,8 +143,8 @@ exports.activate = function (opts) {
return;
}
- elem.find(".add-task").val("").focus();
- elem.find(".add-desc").val("").focus();
+ elem.find(".add-task").val("").trigger("focus");
+ elem.find(".add-desc").val("").trigger("focus");
const task_exists = task_data.name_in_use(task);
if (task_exists) {
diff --git a/static/js/ui.js b/static/js/ui.js
index b47ab538c4d..43c68a12806 100644
--- a/static/js/ui.js
+++ b/static/js/ui.js
@@ -178,7 +178,7 @@ exports.maybe_show_deprecation_notice = function (key) {
if (!shown_deprecation_notices.includes(key)) {
$("#deprecation-notice-modal").modal("show");
$("#deprecation-notice-message").text(message);
- $("#close-deprecation-notice").focus();
+ $("#close-deprecation-notice").trigger("focus");
shown_deprecation_notices.push(key);
if (localstorage.supported()) {
localStorage.setItem(
@@ -206,7 +206,7 @@ exports.set_compose_textarea_handlers = function () {
};
exports.restore_compose_cursor = function () {
- $("#compose-textarea").focus().caret(saved_compose_cursor);
+ $("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
};
exports.initialize = function () {
diff --git a/static/js/ui_util.js b/static/js/ui_util.js
index e063b6ea50d..bda79d0be36 100644
--- a/static/js/ui_util.js
+++ b/static/js/ui_util.js
@@ -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
exports.place_caret_at_end = function (el) {
- el.focus();
+ el.trigger("focus");
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
const range = document.createRange();
diff --git a/static/js/upload.js b/static/js/upload.js
index 8fd897e1526..441612a635f 100644
--- a/static/js/upload.js
+++ b/static/js/upload.js
@@ -127,7 +127,7 @@ exports.upload_files = function (uppy, config, files) {
});
compose_ui.autosize_textarea();
uppy.cancelAll();
- exports.get_item("textarea", config).focus();
+ exports.get_item("textarea", config).trigger("focus");
setTimeout(() => {
exports.hide_upload_status(config);
}, 500);
diff --git a/static/js/user_pill.js b/static/js/user_pill.js
index 1aca5f4f600..405f9458c11 100644
--- a/static/js/user_pill.js
+++ b/static/js/user_pill.js
@@ -145,7 +145,7 @@ exports.set_up_typeahead_on_pills = function (input, pills, update_func, source)
},
updater: function (user) {
exports.append_user(user, pills);
- input.focus();
+ input.trigger("focus");
update_func();
},
stopAdvance: true,
diff --git a/static/js/user_search.js b/static/js/user_search.js
index 4fb9bfa22c0..65d01d35b55 100644
--- a/static/js/user_search.js
+++ b/static/js/user_search.js
@@ -31,7 +31,7 @@ const user_search = function (opts) {
}
$input.val("");
- $input.blur();
+ $input.trigger("blur");
opts.reset_items();
};
@@ -71,7 +71,7 @@ const user_search = function (opts) {
};
self.close_widget = function () {
- $input.blur();
+ $input.trigger("blur");
self.hide_widget();
opts.reset_items();
};
@@ -91,7 +91,7 @@ const user_search = function (opts) {
self.initiate_search = function () {
self.expand_column();
self.show_widget();
- $input.focus();
+ $input.trigger("focus");
};
self.toggle_filter_displayed = function () {
diff --git a/static/js/user_status_ui.js b/static/js/user_status_ui.js
index 1370f46eb21..1f060c0a7b8 100644
--- a/static/js/user_status_ui.js
+++ b/static/js/user_status_ui.js
@@ -18,8 +18,8 @@ exports.open_overlay = function () {
const old_status_text = user_status.get_status_text(user_id);
const field = exports.input_field();
field.val(old_status_text);
- field.select();
- field.focus();
+ field.trigger("select");
+ field.trigger("focus");
exports.toggle_clear_message_button();
const button = exports.submit_button();