Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/navigate.js to ES6 module.

Anders Kaseorg0200f48a12ac
diff --git a/.eslintrc.json b/.eslintrc.json
index 3f1e89e5564..d0b04cac860 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -163,7 +163,6 @@
"message_store": false,
"message_util": false,
"narrow": false,
- "navigate": false,
"notifications": false,
"padded_widget": false,
"page_params": false,
diff --git a/frontend_tests/node_tests/hashchange.js b/frontend_tests/node_tests/hashchange.js
index f6b70f9624a..ff10c28319e 100644
--- a/frontend_tests/node_tests/hashchange.js
+++ b/frontend_tests/node_tests/hashchange.js
@@ -48,7 +48,6 @@ const people = zrequire("people");
const hash_util = zrequire("hash_util");
const hashchange = zrequire("hashchange");
const stream_data = zrequire("stream_data");
-zrequire("navigate");
const recent_topics = zrequire("recent_topics");
recent_topics.show = () => {};
diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js
index 7972744fd26..78376ae6371 100644
--- a/frontend_tests/node_tests/hotkey.js
+++ b/frontend_tests/node_tests/hotkey.js
@@ -90,7 +90,8 @@ rewiremock("../../static/js/message_edit").with(message_edit);
const muting_ui = {__esModule: true};
rewiremock("../../static/js/muting_ui").with(muting_ui);
const narrow = set_global("narrow", {});
-const navigate = set_global("navigate", {});
+const navigate = {__esModule: true};
+rewiremock("../../static/js/navigate").with(navigate);
const reactions = set_global("reactions", {});
const search = {__esModule: true};
rewiremock("../../static/js/search").with(search);
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 3a6b5820fdc..d45c3259c2a 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -28,7 +28,6 @@ import "../compose_actions";
import "../subs";
import "../ui";
import "../composebox_typeahead";
-import "../navigate";
import "../list_util";
import "../hotkey";
import "../notifications";
diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js
index 7c45bed70f6..c1eedd37505 100644
--- a/static/js/gear_menu.js
+++ b/static/js/gear_menu.js
@@ -1,4 +1,5 @@
import * as message_viewport from "./message_viewport";
+import * as navigate from "./navigate";
/*
For various historical reasons there isn't one
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index d037bce9180..05fb95f7504 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -37,7 +37,6 @@ declare let message_list: any;
declare let message_store: any;
declare let message_util: any;
declare let narrow: any;
-declare let navigate: any;
declare let notifications: any;
declare let padded_widget: any;
declare let page_params: any;
diff --git a/static/js/hashchange.js b/static/js/hashchange.js
index 46f95a3c6b8..ed24c5428d9 100644
--- a/static/js/hashchange.js
+++ b/static/js/hashchange.js
@@ -5,6 +5,7 @@ const floating_recipient_bar = require("./floating_recipient_bar");
const info_overlay = require("./info_overlay");
const invite = require("./invite");
const message_viewport = require("./message_viewport");
+const navigate = require("./navigate");
const overlays = require("./overlays");
const search = require("./search");
const settings_panel_menu = require("./settings_panel_menu");
diff --git a/static/js/hotkey.js b/static/js/hotkey.js
index e4e50dde28f..d47eecb259b 100644
--- a/static/js/hotkey.js
+++ b/static/js/hotkey.js
@@ -13,6 +13,7 @@ const gear_menu = require("./gear_menu");
const lightbox = require("./lightbox");
const message_edit = require("./message_edit");
const muting_ui = require("./muting_ui");
+const navigate = require("./navigate");
const overlays = require("./overlays");
const popovers = require("./popovers");
const search = require("./search");
diff --git a/static/js/navigate.js b/static/js/navigate.js
index 552ecf5e610..06cc219d40c 100644
--- a/static/js/navigate.js
+++ b/static/js/navigate.js
@@ -1,22 +1,20 @@
-"use strict";
-
-const message_viewport = require("./message_viewport");
-const rows = require("./rows");
+import * as message_viewport from "./message_viewport";
+import * as rows from "./rows";
function go_to_row(msg_id) {
current_msg_list.select_id(msg_id, {then_scroll: true, from_scroll: true});
}
-exports.up = function () {
+export function up() {
message_viewport.set_last_movement_direction(-1);
const msg_id = current_msg_list.prev();
if (msg_id === undefined) {
return;
}
go_to_row(msg_id);
-};
+}
-exports.down = function (with_centering) {
+export function down(with_centering) {
message_viewport.set_last_movement_direction(1);
if (current_msg_list.is_at_end()) {
@@ -41,22 +39,22 @@ exports.down = function (with_centering) {
return;
}
go_to_row(msg_id);
-};
+}
-exports.to_home = function () {
+export function to_home() {
message_viewport.set_last_movement_direction(-1);
const first_id = current_msg_list.first().id;
current_msg_list.select_id(first_id, {then_scroll: true, from_scroll: true});
-};
+}
-exports.to_end = function () {
+export function to_end() {
const next_id = current_msg_list.last().id;
message_viewport.set_last_movement_direction(1);
current_msg_list.select_id(next_id, {then_scroll: true, from_scroll: true});
if (current_msg_list.can_mark_messages_read()) {
unread_ops.mark_current_list_as_read();
}
-};
+}
function amount_to_paginate() {
// Some day we might have separate versions of this function
@@ -86,7 +84,7 @@ function amount_to_paginate() {
return delta;
}
-exports.page_up_the_right_amount = function () {
+export function page_up_the_right_amount() {
// This function's job is to scroll up the right amount,
// after the user hits Page Up. We do this ourselves
// because we can't rely on the browser to account for certain
@@ -96,52 +94,51 @@ exports.page_up_the_right_amount = function () {
// scroll handlers, not here.
const delta = amount_to_paginate();
message_viewport.scrollTop(message_viewport.scrollTop() - delta);
-};
+}
-exports.page_down_the_right_amount = function () {
+export function page_down_the_right_amount() {
// see also: page_up_the_right_amount
const delta = amount_to_paginate();
message_viewport.scrollTop(message_viewport.scrollTop() + delta);
-};
+}
-exports.page_up = function () {
+export function page_up() {
if (message_viewport.at_top() && !current_msg_list.empty()) {
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
} else {
- exports.page_up_the_right_amount();
+ page_up_the_right_amount();
}
-};
+}
-exports.page_down = function () {
+export function page_down() {
if (message_viewport.at_bottom() && !current_msg_list.empty()) {
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
if (current_msg_list.can_mark_messages_read()) {
unread_ops.mark_current_list_as_read();
}
} else {
- exports.page_down_the_right_amount();
+ page_down_the_right_amount();
}
-};
+}
-exports.scroll_to_selected = function () {
+export function scroll_to_selected() {
const selected_row = current_msg_list.selected_row();
if (selected_row && selected_row.length !== 0) {
message_viewport.recenter_view(selected_row);
}
-};
+}
let scroll_to_selected_planned = false;
-exports.plan_scroll_to_selected = function () {
+
+export function plan_scroll_to_selected() {
scroll_to_selected_planned = true;
-};
+}
-exports.maybe_scroll_to_selected = function () {
+export function maybe_scroll_to_selected() {
// If we have made a plan to scroll to the selected message but
// deferred doing so, do so here.
if (scroll_to_selected_planned) {
- exports.scroll_to_selected();
+ scroll_to_selected();
scroll_to_selected_planned = false;
}
-};
-
-window.navigate = exports;
+}
diff --git a/static/js/notifications.js b/static/js/notifications.js
index 8b4484ad3b1..614d9a746be 100644
--- a/static/js/notifications.js
+++ b/static/js/notifications.js
@@ -10,6 +10,7 @@ const channel = require("./channel");
const favicon = require("./favicon");
const muting = require("./muting");
const narrow_state = require("./narrow_state");
+const navigate = require("./navigate");
const people = require("./people");
const settings_config = require("./settings_config");
const spoilers = require("./spoilers");
diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js
index 92735cbd0b7..bc6e8c6d1cd 100644
--- a/static/js/recent_topics.js
+++ b/static/js/recent_topics.js
@@ -9,6 +9,7 @@ const ListWidget = require("./list_widget");
const {localstorage} = require("./localstorage");
const muting = require("./muting");
const narrow_state = require("./narrow_state");
+const navigate = require("./navigate");
const people = require("./people");
const recent_senders = require("./recent_senders");
const stream_data = require("./stream_data");
diff --git a/static/js/resize.js b/static/js/resize.js
index a9b4b3bbc06..45502a01ef5 100644
--- a/static/js/resize.js
+++ b/static/js/resize.js
@@ -2,6 +2,7 @@ import autosize from "autosize";
import * as condense from "./condense";
import * as message_viewport from "./message_viewport";
+import * as navigate from "./navigate";
import * as popovers from "./popovers";
import * as util from "./util";
diff --git a/static/js/stream_muting.js b/static/js/stream_muting.js
index 017941a76a1..27a663d3f79 100644
--- a/static/js/stream_muting.js
+++ b/static/js/stream_muting.js
@@ -1,5 +1,6 @@
import * as message_scroll from "./message_scroll";
import * as message_viewport from "./message_viewport";
+import * as navigate from "./navigate";
import * as overlays from "./overlays";
export function update_is_muted(sub, value) {
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index 5a5a0b06373..0d345583908 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -26,6 +26,7 @@ const message_edit = require("./message_edit");
const message_scroll = require("./message_scroll");
const message_viewport = require("./message_viewport");
const muting = require("./muting");
+const navigate = require("./navigate");
const overlays = require("./overlays");
const people = require("./people");
const pm_conversations = require("./pm_conversations");