Skip to content

Commit

Permalink
hashchange: Call stop_auto_scrolling() directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Howell authored and timabbott committed Dec 4, 2018
1 parent 6bfcebe commit 7a2527a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
33 changes: 11 additions & 22 deletions frontend_tests/node_tests/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {});
Expand Down Expand Up @@ -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;
Expand All @@ -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);
};
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
]);

Expand All @@ -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',
]);

Expand All @@ -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',
]);

Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions static/js/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion static/js/message_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 7a2527a

Please sign in to comment.