Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_topics: Set focus to element on click.
Aman Agrawal493c00f2adb2
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex bdf57ccb3ad..8c630d2a27d 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -427,10 +427,13 @@ export function initialize() {mute_topic($(e.target));});+ // RECENT TOPICS+$("body").on("keydown", ".on_hover_topic_mute", convert_enter_to_click);- $("body").on("click", ".on_hover_topic_unmute", (e) => {+ $("body").on("click", "#recent_topics_table .on_hover_topic_unmute", (e) => {e.stopPropagation();+ recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.mute);const stream_id = Number.parseInt($(e.currentTarget).attr("data-stream-id"), 10);const topic = $(e.currentTarget).attr("data-topic-name");muting_ui.unmute_topic(stream_id, topic);@@ -438,15 +441,21 @@ export function initialize() {$("body").on("keydown", ".on_hover_topic_unmute", convert_enter_to_click);- // RECENT TOPICS+ $("body").on("click", "#recent_topics_table .on_hover_topic_mute", (e) => {+ e.stopPropagation();+ const $elt = $(e.target);+ recent_topics.focus_clicked_element($elt, recent_topics.COLUMNS.mute);+ mute_topic($elt);+ });$("body").on("click", "#recent_topics_search", (e) => {e.stopPropagation();recent_topics.change_focused_element(e, "click");});- $("body").on("click", ".on_hover_topic_read", (e) => {+ $("body").on("click", "#recent_topics_table .on_hover_topic_read", (e) => {e.stopPropagation();+ recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.read);const stream_id = Number.parseInt($(e.currentTarget).attr("data-stream-id"), 10);const topic = $(e.currentTarget).attr("data-topic-name");unread_ops.mark_topic_as_read(stream_id, topic);@@ -456,17 +465,20 @@ export function initialize() {$("body").on("click", ".btn-recent-filters", (e) => {e.stopPropagation();+ recent_topics.change_focused_element(e, "click");recent_topics.set_filter(e.currentTarget.dataset.filter);recent_topics.update_filters_view();});$("body").on("click", "td.recent_topic_stream", (e) => {e.stopPropagation();+ recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.stream);window.location.href = $(e.currentTarget).find("a").attr("href");});$("body").on("click", "td.recent_topic_name", (e) => {e.stopPropagation();+ recent_topics.focus_clicked_element($(e.target), recent_topics.COLUMNS.topic);window.location.href = $(e.currentTarget).find("a").attr("href");});diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex 61d5f365d94..82fa543e7b6 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -47,6 +47,13 @@ let row_focus = 0;// Start focus on the topic column, so Down+Enter works to visit a topic.let col_focus = 1;+export const COLUMNS = {+ stream: 0,+ topic: 1,+ mute: 2,+ read: 3,+};+// The number of selectable actions in a recent_topics. Used to// implement wraparound of elements with the right/left keys. Must be// increased when we add new actions, or rethought if we add optional@@ -552,6 +559,12 @@ function is_focus_at_last_table_row() {return row_focus === topic_rows.length - 1;}+export function focus_clicked_element($elt, col) {+ current_focus_elem = "table";+ col_focus = col;+ row_focus = $elt.closest("tr").index();+}+export function change_focused_element(e, input_key) {// Called from hotkeys.js; like all logic in that module,// returning true will cause the caller to do@@ -620,6 +633,9 @@ export function change_focused_element(e, input_key) {}} else if ($elem.hasClass("btn-recent-filters")) {switch (input_key) {+ case "click":+ current_focus_elem = $elem;+ return true;case "shift_tab":case "vim_left":case "left_arrow":