From 7a2527aed1694f86bf6f430b86043d3e25049e56 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 4 Dec 2018 18:08:26 +0000 Subject: [PATCH] hashchange: Call stop_auto_scrolling() directly. --- frontend_tests/node_tests/hashchange.js | 33 +++++++++---------------- static/js/hashchange.js | 4 +-- static/js/message_list.js | 2 +- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js index babe0c8792..6c87eed8e5 100644 --- a/frontend_tests/node_tests/hashchange.js +++ b/frontend_tests/node_tests/hashchange.js @@ -17,6 +17,7 @@ set_global('drafts', {}); set_global('favicon', {}); set_global('floating_recipient_bar', {}); set_global('info_overlay', {}); +set_global('message_viewport', {}); set_global('narrow', {}); set_global('overlays', {}); set_global('settings', {}); @@ -113,17 +114,6 @@ run_test('people_slugs', () => { assert.equal(hash, '#narrow/pm-with/42-alice'); }); -function stub_trigger(f) { - set_global('$', () => { - return { - trigger: f, - }; - }); - $.Event = (name) => { - assert.equal(name, 'zuliphashchange.zulip'); - }; -} - function test_helper() { var events = []; var narrow_terms; @@ -138,14 +128,13 @@ function test_helper() { stub('drafts', 'launch'); stub('favicon', 'reset'); stub('floating_recipient_bar', 'update'); + stub('message_viewport', 'stop_auto_scrolling'); stub('narrow', 'deactivate'); stub('overlays', 'close_for_hash_change'); stub('settings', 'setup_page'); stub('subs', 'launch'); stub('ui_util', 'blur_active_element'); - stub_trigger(() => { events.push('trigger event'); }); - ui_util.change_tab_to = (hash) => { events.push('change_tab_to ' + hash); }; @@ -181,7 +170,7 @@ run_test('hash_interactions', () => { hashchange.initialize(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'change_tab_to #home', 'narrow.deactivate', 'floating_recipient_bar.update', @@ -191,7 +180,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'change_tab_to #home', 'narrow.deactivate', 'floating_recipient_bar.update', @@ -203,7 +192,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'change_tab_to #home', 'narrow.activate', 'floating_recipient_bar.update', @@ -217,7 +206,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'change_tab_to #home', 'narrow.activate', 'floating_recipient_bar.update', @@ -240,7 +229,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'info: keyboard-shortcuts', ]); @@ -250,7 +239,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'info: message-formatting', ]); @@ -260,7 +249,7 @@ run_test('hash_interactions', () => { window.onhashchange(); helper.assert_events([ 'overlays.close_for_hash_change', - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'info: search-operators', ]); @@ -316,7 +305,7 @@ run_test('save_narrow', () => { hashchange.save_narrow(operators); helper.assert_events([ - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'favicon.reset', ]); assert.equal(window.location.hash, '#narrow/is/private'); @@ -333,7 +322,7 @@ run_test('save_narrow', () => { helper.clear_events(); hashchange.save_narrow(operators); helper.assert_events([ - 'trigger event', + 'message_viewport.stop_auto_scrolling', 'favicon.reset', ]); assert.equal(url_pushed, 'http://example.com/#narrow/is/starred'); diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 0bf4677816..eb7c6b5291 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -34,7 +34,7 @@ exports.changehash = function (newhash) { if (changing_hash) { return; } - $(document).trigger($.Event('zuliphashchange.zulip')); + message_viewport.stop_auto_scrolling(); set_hash(newhash); favicon.reset(); }; @@ -96,7 +96,7 @@ function do_hashchange_normal(from_reload) { return false; } - $(document).trigger($.Event('zuliphashchange.zulip')); + message_viewport.stop_auto_scrolling(); // NB: In Firefox, window.location.hash is URI-decoded. // Even if the URL bar says #%41%42%43%44, the value here will diff --git a/static/js/message_list.js b/static/js/message_list.js index 7240b8b66f..fcaf3e7471 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -428,7 +428,7 @@ exports.all = new exports.MessageList({ // doing something. Be careful, though, if you try to capture // mousemove, then you will have to contend with the autoscroll // itself generating mousemove events. -$(document).on('message_selected.zulip zuliphashchange.zulip wheel', function () { +$(document).on('message_selected.zulip wheel', function () { message_viewport.stop_auto_scrolling(); });