mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
hashchange: Add hash_util.get_hash_category().
This replaces hashchange.get_main_hash(), which had a slightly misleading name. Also, moving this to hash_util forces us to keep 100% coverage on it.
This commit is contained in:
@@ -63,6 +63,25 @@ run_test('hash_util', () => {
|
||||
encode_decode_operand(operator, operand, 'testing.20123');
|
||||
});
|
||||
|
||||
run_test('test_get_hash_category', () => {
|
||||
assert.deepEqual(
|
||||
hash_util.get_hash_category('streams/subscribed'),
|
||||
'streams'
|
||||
);
|
||||
assert.deepEqual(
|
||||
hash_util.get_hash_category('#settings/display-settings'),
|
||||
'settings'
|
||||
);
|
||||
assert.deepEqual(
|
||||
hash_util.get_hash_category('#drafts'),
|
||||
'drafts'
|
||||
);
|
||||
assert.deepEqual(
|
||||
hash_util.get_hash_category('invites'),
|
||||
'invites'
|
||||
);
|
||||
});
|
||||
|
||||
run_test('test_parse_narrow', () => {
|
||||
assert.deepEqual(
|
||||
hash_util.parse_narrow(['narrow', 'stream', '11-social']),
|
||||
|
||||
@@ -2,6 +2,11 @@ var hash_util = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
exports.get_hash_category = function (hash) {
|
||||
// given "#streams/subscribed", returns "streams"
|
||||
return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
|
||||
};
|
||||
|
||||
// Some browsers zealously URI-decode the contents of
|
||||
// window.location.hash. So we hide our URI-encoding
|
||||
// by replacing % with . (like MediaWiki).
|
||||
|
||||
@@ -59,10 +59,6 @@ var state = {
|
||||
old_hash: typeof window !== "undefined" ? window.location.hash : "#",
|
||||
};
|
||||
|
||||
function get_main_hash(hash) {
|
||||
return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
|
||||
}
|
||||
|
||||
function get_hash_components() {
|
||||
var hash = window.location.hash.split(/\//);
|
||||
|
||||
@@ -75,7 +71,7 @@ function get_hash_components() {
|
||||
function is_overlay_hash(hash) {
|
||||
// Hash changes within this list are overlays and should not unnarrow (etc.)
|
||||
var overlay_list = ["streams", "drafts", "settings", "organization", "invite"];
|
||||
var main_hash = get_main_hash(hash);
|
||||
var main_hash = hash_util.get_hash_category(hash);
|
||||
|
||||
return overlay_list.indexOf(main_hash) > -1;
|
||||
}
|
||||
@@ -141,8 +137,8 @@ function do_hashchange_normal(from_reload) {
|
||||
}
|
||||
|
||||
function do_hashchange_overlay(old_hash) {
|
||||
var base = get_main_hash(window.location.hash);
|
||||
var old_base = get_main_hash(old_hash);
|
||||
var base = hash_util.get_hash_category(window.location.hash);
|
||||
var old_base = hash_util.get_hash_category(old_hash);
|
||||
|
||||
var coming_from_overlay = is_overlay_hash(old_hash || '#');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user