diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js index 5c1f7dd440..dfc3f29288 100644 --- a/static/js/gear_menu.js +++ b/static/js/gear_menu.js @@ -39,7 +39,7 @@ exports.initialize = function () { viewport.scrollTop(scroll_positions[target_tab]); } else { if (target_tab === '#home') { - scroll_to_selected(); + navigate.scroll_to_selected(); } else { viewport.scrollTop(0); } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index a6bd58e0b7..0902e9ca77 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -577,7 +577,7 @@ MessageListView.prototype = { // autoscroll_forever: if we're on the last message, keep us on the last message if (last_message_was_selected && page_params.autoscroll_forever) { this.list.select_id(this.list.last().id, {from_rendering: true}); - scroll_to_selected(); + navigate.scroll_to_selected(); this.list.reselect_selected_id(); return; } @@ -597,7 +597,7 @@ MessageListView.prototype = { // autoscroll_forever: if we've sent a message, move pointer at least that far. if (page_params.autoscroll_forever && id_of_last_message_sent_by_us > -1 && (rows.last_visible().offset().top - this.list.selected_row().offset().top) < (viewport.height())) { this.list.select_id(id_of_last_message_sent_by_us, {from_rendering: true}); - scroll_to_selected(); + navigate.scroll_to_selected(); return; } diff --git a/static/js/navigate.js b/static/js/navigate.js index 9bb44c2d75..d82d0397b0 100644 --- a/static/js/navigate.js +++ b/static/js/navigate.js @@ -102,12 +102,19 @@ exports.cycle_stream = function (direction) { narrow.by('stream', nextStream.data('name')); }; +exports.scroll_to_selected = function () { + var selected_row = current_msg_list.selected_row(); + if (selected_row && (selected_row.length !== 0)) { + recenter_view(selected_row); + } +}; + exports.maybe_scroll_to_selected = function () { // If we have been previously instructed to re-center to the // selected message, then do so if (pointer.recenter_pointer_on_display) { - scroll_to_selected(); + exports.scroll_to_selected(); pointer.recenter_pointer_on_display = false; } }; diff --git a/static/js/notifications.js b/static/js/notifications.js index a0ab624232..990e7fbd15 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -582,7 +582,7 @@ exports.register_click_handlers = function () { $('#out-of-view-notification').on('click', '.compose_notification_scroll_to_message', function (e) { var msgid = $(e.currentTarget).data('msgid'); current_msg_list.select_id(msgid); - scroll_to_selected(); + navigate.scroll_to_selected(); e.stopPropagation(); e.preventDefault(); }); diff --git a/static/js/resize.js b/static/js/resize.js index 5cb262fd43..ebaad4c357 100644 --- a/static/js/resize.js +++ b/static/js/resize.js @@ -254,7 +254,7 @@ exports.handler = function (e) { // but before we've loaded in the messages; in that case, don't // try to scroll to one. if (current_msg_list.selected_id() !== -1) { - scroll_to_selected(); + navigate.scroll_to_selected(); } }; diff --git a/static/js/zulip.js b/static/js/zulip.js index b41f4e6924..19306b2fb7 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -49,14 +49,6 @@ function recenter_view(message, opts) { } } -function scroll_to_selected() { - var selected_row = current_msg_list.selected_row(); - if (selected_row && (selected_row.length !== 0)) { - recenter_view(selected_row); - } -} - - function get_private_message_recipient(message, attr, fallback_attr) { var recipient, i; var other_recipients = _.filter(message.display_recipient, diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 5df1bef91b..c7d668bf64 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -55,7 +55,7 @@ var globals = // zulip.js + ' home_msg_list current_msg_list' + ' respond_to_message recenter_view' - + ' scroll_to_selected get_private_message_recipient' + + ' get_private_message_recipient' + ' process_loaded_for_unread' + ' recent_subjects unread_subjects' ;