diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index 058668857b..476f94a41d 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -177,11 +177,11 @@ function stubbing(func_name_to_stub, test_function) { } _.each([return_true, return_false], function (is_settings_page) { - _.each([return_true, return_false], function (home_tab_obscured) { + _.each([return_true, return_false], function (is_active) { _.each([return_true, return_false], function (is_info_overlay) { hotkey.is_settings_page = is_settings_page; - set_global('ui_state', {home_tab_obscured: home_tab_obscured, - is_info_overlay: is_info_overlay}); + set_global('modals', {is_active: is_active}); + set_global('ui_state', {is_info_overlay: is_info_overlay}); test_normal_typing(); }); diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index 89659dd956..0363d96b08 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -314,7 +314,7 @@ $(function () { }); $(".brand").on('click', function (e) { - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { ui_util.change_tab_to('#home'); } else { narrow.restore_home_state(); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index e5ffd47e7a..c04b4949ff 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -456,7 +456,7 @@ exports.process_hotkey = function (e, hotkey) { return false; } - if (hotkey.message_view_only && ui_state.home_tab_obscured()) { + if (hotkey.message_view_only && modals.is_active()) { return false; } diff --git a/static/js/modals.js b/static/js/modals.js index 10cd7db836..9247ded770 100644 --- a/static/js/modals.js +++ b/static/js/modals.js @@ -12,6 +12,10 @@ function reset_state() { open_modal_name = undefined; } +exports.is_active = function () { + return !!open_modal_name; +}; + exports.open_overlay = function (opts) { if (!opts.name || !opts.overlay || !opts.on_close) { blueslip.error('Programming error in open_modal'); diff --git a/static/js/narrow.js b/static/js/narrow.js index a389f71b68..f5a2d0e950 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -461,7 +461,7 @@ exports.restore_home_state = function () { // If we click on the Home link from another nav pane, just go // back to the state you were in (possibly still narrowed) before // you left the Home pane. - if (!ui_state.home_tab_obscured()) { + if (!modals.is_active()) { exports.deactivate(); } navigate.maybe_scroll_to_selected(); diff --git a/static/js/stream_list.js b/static/js/stream_list.js index e2487355b2..3916fcf7f9 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -427,7 +427,7 @@ $(function () { if (e.metaKey || e.ctrlKey) { return; } - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { ui_util.change_tab_to('#home'); } var stream = $(e.target).parents('li').attr('data-name'); @@ -500,7 +500,7 @@ function maybe_select_stream(e) { var topStream = $('#stream_filters li.narrow-filter').first().data('name'); if (topStream !== undefined) { // undefined if there are no results - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { ui_util.change_tab_to('#home'); } exports.clear_and_hide_search(); diff --git a/static/js/stream_muting.js b/static/js/stream_muting.js index 3cf5289357..619d0f3978 100644 --- a/static/js/stream_muting.js +++ b/static/js/stream_muting.js @@ -11,7 +11,7 @@ exports.update_in_home_view = function (sub, value) { var msg_offset; var saved_ypos; // Save our current scroll position - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { saved_ypos = message_viewport.scrollTop(); } else if (home_msg_list === current_msg_list && current_msg_list.selected_row().offset() !== null) { @@ -24,7 +24,7 @@ exports.update_in_home_view = function (sub, value) { message_util.add_messages(message_list.all.all_messages(), home_msg_list); // Ensure we're still at the same scroll position - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { message_viewport.scrollTop(saved_ypos); } else if (home_msg_list === current_msg_list) { // We pass use_closest to handle the case where the diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 89bfc95ff0..8d961f7be4 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -212,7 +212,7 @@ exports.set_click_handlers = function (callbacks) { // In a more componentized world, we would delegate some // of this stuff back up to our parents. - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { ui_util.change_tab_to('#home'); } diff --git a/static/js/tutorial.js b/static/js/tutorial.js index 1316433ad7..30df587742 100644 --- a/static/js/tutorial.js +++ b/static/js/tutorial.js @@ -504,7 +504,7 @@ function welcome() { } exports.start = function () { - if (ui_state.home_tab_obscured()) { + if (modals.is_active()) { ui_util.change_tab_to('#home'); } narrow.deactivate(); diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 49442393d3..3f03e57541 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -68,7 +68,7 @@ $(function () { }); message_viewport.message_pane.mousewheel(function (e, delta) { - if (!ui_state.home_tab_obscured()) { + if (!modals.is_active()) { // In the message view, we use a throttled mousewheel handler. throttled_mousewheelhandler(e, delta); } diff --git a/static/js/ui_state.js b/static/js/ui_state.js index a46f588cab..b92efe3ec9 100644 --- a/static/js/ui_state.js +++ b/static/js/ui_state.js @@ -2,14 +2,6 @@ var ui_state = (function () { var exports = {}; -exports.home_tab_obscured = function () { - if ($('.overlay.show').length > 0) { - return 'modal'; - } - - return false; -}; - exports.is_info_overlay = function () { return ($(".informational-overlays").hasClass("show")); };