mirror of https://github.com/zulip/zulip.git
js: Convert static/js/hashchange.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
c94ffb5319
commit
e30df92944
|
@ -144,7 +144,6 @@
|
||||||
"emoji_picker": false,
|
"emoji_picker": false,
|
||||||
"favicon": false,
|
"favicon": false,
|
||||||
"flatpickr": false,
|
"flatpickr": false,
|
||||||
"hashchange": false,
|
|
||||||
"helpers": false,
|
"helpers": false,
|
||||||
"history": false,
|
"history": false,
|
||||||
"home_msg_list": false,
|
"home_msg_list": false,
|
||||||
|
|
|
@ -78,9 +78,11 @@ const condense = {__esModule: true};
|
||||||
rewiremock("../../static/js/condense").with(condense);
|
rewiremock("../../static/js/condense").with(condense);
|
||||||
const drafts = {__esModule: true};
|
const drafts = {__esModule: true};
|
||||||
rewiremock("../../static/js/drafts").with(drafts);
|
rewiremock("../../static/js/drafts").with(drafts);
|
||||||
const hashchange = set_global("hashchange", {
|
const hashchange = {
|
||||||
|
__esModule: true,
|
||||||
in_recent_topics_hash: () => false,
|
in_recent_topics_hash: () => false,
|
||||||
});
|
};
|
||||||
|
rewiremock("../../static/js/hashchange").with(hashchange);
|
||||||
rewiremock("../../static/js/info_overlay").with({});
|
rewiremock("../../static/js/info_overlay").with({});
|
||||||
const lightbox = {__esModule: true};
|
const lightbox = {__esModule: true};
|
||||||
rewiremock("../../static/js/lightbox").with(lightbox);
|
rewiremock("../../static/js/lightbox").with(lightbox);
|
||||||
|
|
|
@ -19,7 +19,6 @@ rewiremock("../../static/js/resize").with({
|
||||||
rewiremock.enable();
|
rewiremock.enable();
|
||||||
|
|
||||||
const hash_util = zrequire("hash_util");
|
const hash_util = zrequire("hash_util");
|
||||||
zrequire("hashchange");
|
|
||||||
const compose_state = zrequire("compose_state");
|
const compose_state = zrequire("compose_state");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
|
|
|
@ -17,7 +17,8 @@ const compose = {__esModule: true};
|
||||||
rewiremock("../../static/js/compose").with(compose);
|
rewiremock("../../static/js/compose").with(compose);
|
||||||
const compose_actions = set_global("compose_actions", {});
|
const compose_actions = set_global("compose_actions", {});
|
||||||
set_global("current_msg_list", {});
|
set_global("current_msg_list", {});
|
||||||
const hashchange = set_global("hashchange", {});
|
const hashchange = {__esModule: true};
|
||||||
|
rewiremock("../../static/js/hashchange").with(hashchange);
|
||||||
set_global("home_msg_list", {});
|
set_global("home_msg_list", {});
|
||||||
const message_fetch = set_global("message_fetch", {});
|
const message_fetch = set_global("message_fetch", {});
|
||||||
const message_list = set_global("message_list", {
|
const message_list = set_global("message_list", {
|
||||||
|
|
|
@ -13,7 +13,7 @@ const noop = () => {};
|
||||||
stub_templates(() => noop);
|
stub_templates(() => noop);
|
||||||
|
|
||||||
rewiremock("../../static/js/channel").with({});
|
rewiremock("../../static/js/channel").with({});
|
||||||
set_global("hashchange", {update_browser_history: noop});
|
rewiremock("../../static/js/hashchange").with({update_browser_history: noop});
|
||||||
rewiremock("../../static/js/hash_util").with({
|
rewiremock("../../static/js/hash_util").with({
|
||||||
stream_edit_uri: noop,
|
stream_edit_uri: noop,
|
||||||
by_stream_uri: noop,
|
by_stream_uri: noop,
|
||||||
|
|
|
@ -73,7 +73,7 @@ rewiremock("../../static/js/compose_pm_pill").with({initialize() {}});
|
||||||
rewiremock("../../static/js/drafts").with({initialize() {}});
|
rewiremock("../../static/js/drafts").with({initialize() {}});
|
||||||
set_global("emoji_picker", {initialize() {}});
|
set_global("emoji_picker", {initialize() {}});
|
||||||
rewiremock("../../static/js/gear_menu").with({initialize() {}});
|
rewiremock("../../static/js/gear_menu").with({initialize() {}});
|
||||||
set_global("hashchange", {initialize() {}});
|
rewiremock("../../static/js/hashchange").with({initialize() {}});
|
||||||
set_global("hotspots", {initialize() {}});
|
set_global("hotspots", {initialize() {}});
|
||||||
// Accesses home_msg_list, which is a lot of complexity to set up
|
// Accesses home_msg_list, which is a lot of complexity to set up
|
||||||
set_global("message_fetch", {initialize() {}});
|
set_global("message_fetch", {initialize() {}});
|
||||||
|
|
|
@ -30,7 +30,6 @@ import "../ui";
|
||||||
import "../composebox_typeahead";
|
import "../composebox_typeahead";
|
||||||
import "../hotkey";
|
import "../hotkey";
|
||||||
import "../notifications";
|
import "../notifications";
|
||||||
import "../hashchange";
|
|
||||||
import "../message_flags";
|
import "../message_flags";
|
||||||
import "../starred_messages";
|
import "../starred_messages";
|
||||||
import "../alert_words_ui";
|
import "../alert_words_ui";
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as channel from "./channel";
|
||||||
import * as compose from "./compose";
|
import * as compose from "./compose";
|
||||||
import * as compose_state from "./compose_state";
|
import * as compose_state from "./compose_state";
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as message_edit from "./message_edit";
|
import * as message_edit from "./message_edit";
|
||||||
import * as message_edit_history from "./message_edit_history";
|
import * as message_edit_history from "./message_edit_history";
|
||||||
import * as muting_ui from "./muting_ui";
|
import * as muting_ui from "./muting_ui";
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
|
|
||||||
if (window.electron_bridge !== undefined) {
|
if (window.electron_bridge !== undefined) {
|
||||||
window.electron_bridge.on_event("logout", () => {
|
window.electron_bridge.on_event("logout", () => {
|
||||||
$("#logout_form").trigger("submit");
|
$("#logout_form").trigger("submit");
|
||||||
|
@ -11,5 +13,3 @@ if (window.electron_bridge !== undefined) {
|
||||||
hashchange.go_to_location("settings/notifications");
|
hashchange.go_to_location("settings/notifications");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import render_draft_table_body from "../templates/draft_table_body.hbs";
|
||||||
import * as compose from "./compose";
|
import * as compose from "./compose";
|
||||||
import * as compose_fade from "./compose_fade";
|
import * as compose_fade from "./compose_fade";
|
||||||
import * as compose_state from "./compose_state";
|
import * as compose_state from "./compose_state";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import {localstorage} from "./localstorage";
|
import {localstorage} from "./localstorage";
|
||||||
import * as markdown from "./markdown";
|
import * as markdown from "./markdown";
|
||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as message_viewport from "./message_viewport";
|
import * as message_viewport from "./message_viewport";
|
||||||
import * as navigate from "./navigate";
|
import * as navigate from "./navigate";
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ declare let current_msg_list: any;
|
||||||
declare let emoji: any;
|
declare let emoji: any;
|
||||||
declare let emoji_picker: any;
|
declare let emoji_picker: any;
|
||||||
declare let favicon: any;
|
declare let favicon: any;
|
||||||
declare let hashchange: any;
|
|
||||||
declare let helpers: any;
|
declare let helpers: any;
|
||||||
declare let home_msg_list: any;
|
declare let home_msg_list: any;
|
||||||
declare let hotspots: any;
|
declare let hotspots: any;
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
"use strict";
|
import * as drafts from "./drafts";
|
||||||
|
import * as floating_recipient_bar from "./floating_recipient_bar";
|
||||||
const drafts = require("./drafts");
|
import * as hash_util from "./hash_util";
|
||||||
const floating_recipient_bar = require("./floating_recipient_bar");
|
import * as info_overlay from "./info_overlay";
|
||||||
const hash_util = require("./hash_util");
|
import * as invite from "./invite";
|
||||||
const info_overlay = require("./info_overlay");
|
import * as message_viewport from "./message_viewport";
|
||||||
const invite = require("./invite");
|
import * as navigate from "./navigate";
|
||||||
const message_viewport = require("./message_viewport");
|
import * as overlays from "./overlays";
|
||||||
const navigate = require("./navigate");
|
import * as search from "./search";
|
||||||
const overlays = require("./overlays");
|
import * as settings_panel_menu from "./settings_panel_menu";
|
||||||
const search = require("./search");
|
import * as top_left_corner from "./top_left_corner";
|
||||||
const settings_panel_menu = require("./settings_panel_menu");
|
import * as ui_util from "./ui_util";
|
||||||
const top_left_corner = require("./top_left_corner");
|
|
||||||
const ui_util = require("./ui_util");
|
|
||||||
|
|
||||||
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
|
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
|
||||||
// or locally: docs/subsystems/hashchange-system.md
|
// or locally: docs/subsystems/hashchange-system.md
|
||||||
|
@ -55,26 +53,26 @@ function maybe_hide_recent_topics() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.in_recent_topics_hash = function () {
|
export function in_recent_topics_hash() {
|
||||||
return ["recent_topics", "#", ""].includes(window.location.hash);
|
return ["recent_topics", "#", ""].includes(window.location.hash);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.changehash = function (newhash) {
|
export function changehash(newhash) {
|
||||||
if (changing_hash) {
|
if (changing_hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
maybe_hide_recent_topics();
|
maybe_hide_recent_topics();
|
||||||
message_viewport.stop_auto_scrolling();
|
message_viewport.stop_auto_scrolling();
|
||||||
set_hash(newhash);
|
set_hash(newhash);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.save_narrow = function (operators) {
|
export function save_narrow(operators) {
|
||||||
if (changing_hash) {
|
if (changing_hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const new_hash = hash_util.operators_to_hash(operators);
|
const new_hash = hash_util.operators_to_hash(operators);
|
||||||
exports.changehash(new_hash);
|
changehash(new_hash);
|
||||||
};
|
}
|
||||||
|
|
||||||
function activate_home_tab() {
|
function activate_home_tab() {
|
||||||
const coming_from_recent_topics = maybe_hide_recent_topics();
|
const coming_from_recent_topics = maybe_hide_recent_topics();
|
||||||
|
@ -294,7 +292,7 @@ function hashchanged(from_reload, e) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update_browser_history = function (new_hash) {
|
export function update_browser_history(new_hash) {
|
||||||
const old_hash = window.location.hash;
|
const old_hash = window.location.hash;
|
||||||
|
|
||||||
if (!new_hash.startsWith("#")) {
|
if (!new_hash.startsWith("#")) {
|
||||||
|
@ -314,9 +312,9 @@ exports.update_browser_history = function (new_hash) {
|
||||||
state.old_hash = old_hash;
|
state.old_hash = old_hash;
|
||||||
state.is_internal_change = true;
|
state.is_internal_change = true;
|
||||||
window.location.hash = new_hash;
|
window.location.hash = new_hash;
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.replace_hash = function (hash) {
|
export function replace_hash(hash) {
|
||||||
if (!window.history.replaceState) {
|
if (!window.history.replaceState) {
|
||||||
// We may have strange behavior with the back button.
|
// We may have strange behavior with the back button.
|
||||||
blueslip.warn("browser does not support replaceState");
|
blueslip.warn("browser does not support replaceState");
|
||||||
|
@ -325,30 +323,28 @@ exports.replace_hash = function (hash) {
|
||||||
|
|
||||||
const url = get_full_url(hash);
|
const url = get_full_url(hash);
|
||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.go_to_location = function (hash) {
|
export function go_to_location(hash) {
|
||||||
// Call this function when you WANT the hashchanged
|
// Call this function when you WANT the hashchanged
|
||||||
// function to run.
|
// function to run.
|
||||||
window.location.hash = hash;
|
window.location.hash = hash;
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.initialize = function () {
|
export function initialize() {
|
||||||
$(window).on("hashchange", (e) => {
|
$(window).on("hashchange", (e) => {
|
||||||
hashchanged(false, e.originalEvent);
|
hashchanged(false, e.originalEvent);
|
||||||
});
|
});
|
||||||
hashchanged(true);
|
hashchanged(true);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.exit_overlay = function (callback) {
|
export function exit_overlay(callback) {
|
||||||
if (is_overlay_hash(window.location.hash)) {
|
if (is_overlay_hash(window.location.hash)) {
|
||||||
ui_util.blur_active_element();
|
ui_util.blur_active_element();
|
||||||
const new_hash = state.hash_before_overlay || "#";
|
const new_hash = state.hash_before_overlay || "#";
|
||||||
exports.update_browser_history(new_hash);
|
update_browser_history(new_hash);
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
window.hashchange = exports;
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import * as copy_and_paste from "./copy_and_paste";
|
||||||
import * as drafts from "./drafts";
|
import * as drafts from "./drafts";
|
||||||
import * as feedback_widget from "./feedback_widget";
|
import * as feedback_widget from "./feedback_widget";
|
||||||
import * as gear_menu from "./gear_menu";
|
import * as gear_menu from "./gear_menu";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as lightbox from "./lightbox";
|
import * as lightbox from "./lightbox";
|
||||||
import * as list_util from "./list_util";
|
import * as list_util from "./list_util";
|
||||||
import * as message_edit from "./message_edit";
|
import * as message_edit from "./message_edit";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as common from "./common";
|
import * as common from "./common";
|
||||||
import * as components from "./components";
|
import * as components from "./components";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as keydown_util from "./keydown_util";
|
import * as keydown_util from "./keydown_util";
|
||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
import * as popovers from "./popovers";
|
import * as popovers from "./popovers";
|
||||||
|
|
|
@ -8,6 +8,7 @@ import render_settings_dev_env_email_access from "../templates/settings/dev_env_
|
||||||
|
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as common from "./common";
|
import * as common from "./common";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
|
|
|
@ -6,6 +6,7 @@ const compose_fade = require("./compose_fade");
|
||||||
const compose_state = require("./compose_state");
|
const compose_state = require("./compose_state");
|
||||||
const condense = require("./condense");
|
const condense = require("./condense");
|
||||||
const {Filter} = require("./filter");
|
const {Filter} = require("./filter");
|
||||||
|
const hashchange = require("./hashchange");
|
||||||
const message_edit = require("./message_edit");
|
const message_edit = require("./message_edit");
|
||||||
const {MessageListData} = require("./message_list_data");
|
const {MessageListData} = require("./message_list_data");
|
||||||
const message_scroll = require("./message_scroll");
|
const message_scroll = require("./message_scroll");
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as popovers from "./popovers";
|
import * as popovers from "./popovers";
|
||||||
|
|
||||||
let active_overlay;
|
let active_overlay;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as compose from "./compose";
|
import * as compose from "./compose";
|
||||||
import * as compose_state from "./compose_state";
|
import * as compose_state from "./compose_state";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import {localstorage} from "./localstorage";
|
import {localstorage} from "./localstorage";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as reload_state from "./reload_state";
|
import * as reload_state from "./reload_state";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const hashchange = require("./hashchange");
|
||||||
const search_pill = require("./search_pill");
|
const search_pill = require("./search_pill");
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as keydown_util from "./keydown_util";
|
import * as keydown_util from "./keydown_util";
|
||||||
import * as popovers from "./popovers";
|
import * as popovers from "./popovers";
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import render_subscription_stream_privacy_modal from "../templates/subscription_
|
||||||
|
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as ListWidget from "./list_widget";
|
import * as ListWidget from "./list_widget";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
|
|
|
@ -8,6 +8,7 @@ import render_unstar_messages_modal from "../templates/unstar_messages_modal.hbs
|
||||||
|
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as message_edit from "./message_edit";
|
import * as message_edit from "./message_edit";
|
||||||
import * as muting from "./muting";
|
import * as muting from "./muting";
|
||||||
import * as muting_ui from "./muting_ui";
|
import * as muting_ui from "./muting_ui";
|
||||||
|
|
|
@ -11,6 +11,7 @@ const channel = require("./channel");
|
||||||
const components = require("./components");
|
const components = require("./components");
|
||||||
const compose_state = require("./compose_state");
|
const compose_state = require("./compose_state");
|
||||||
const hash_util = require("./hash_util");
|
const hash_util = require("./hash_util");
|
||||||
|
const hashchange = require("./hashchange");
|
||||||
const loading = require("./loading");
|
const loading = require("./loading");
|
||||||
const message_live_update = require("./message_live_update");
|
const message_live_update = require("./message_live_update");
|
||||||
const overlays = require("./overlays");
|
const overlays = require("./overlays");
|
||||||
|
|
|
@ -18,6 +18,7 @@ const drafts = require("./drafts");
|
||||||
const echo = require("./echo");
|
const echo = require("./echo");
|
||||||
const emojisets = require("./emojisets");
|
const emojisets = require("./emojisets");
|
||||||
const gear_menu = require("./gear_menu");
|
const gear_menu = require("./gear_menu");
|
||||||
|
const hashchange = require("./hashchange");
|
||||||
const invite = require("./invite");
|
const invite = require("./invite");
|
||||||
const lightbox = require("./lightbox");
|
const lightbox = require("./lightbox");
|
||||||
const markdown = require("./markdown");
|
const markdown = require("./markdown");
|
||||||
|
|
|
@ -3,6 +3,7 @@ import marked from "../third/marked/lib/marked";
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as common from "./common";
|
import * as common from "./common";
|
||||||
import * as feedback_widget from "./feedback_widget";
|
import * as feedback_widget from "./feedback_widget";
|
||||||
|
import * as hashchange from "./hashchange";
|
||||||
import * as night_mode from "./night_mode";
|
import * as night_mode from "./night_mode";
|
||||||
import * as scroll_bar from "./scroll_bar";
|
import * as scroll_bar from "./scroll_bar";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue