mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
hashchange: Add hash_util.get_hash_section().
We'll use this mostly for streams/settings URLs at first.
This commit is contained in:
@@ -82,6 +82,31 @@ run_test('test_get_hash_category', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
run_test('test_get_hash_section', () => {
|
||||||
|
assert.equal(
|
||||||
|
hash_util.get_hash_section('streams/subscribed'),
|
||||||
|
'subscribed'
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
hash_util.get_hash_section('#settings/your-account'),
|
||||||
|
'your-account'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
hash_util.get_hash_section('settings/10/general/'),
|
||||||
|
'10'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
hash_util.get_hash_section('#drafts'),
|
||||||
|
''
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
hash_util.get_hash_section(''),
|
||||||
|
''
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
run_test('test_parse_narrow', () => {
|
run_test('test_parse_narrow', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
hash_util.parse_narrow(['narrow', 'stream', '11-social']),
|
hash_util.parse_narrow(['narrow', 'stream', '11-social']),
|
||||||
|
|||||||
@@ -7,6 +7,18 @@ exports.get_hash_category = function (hash) {
|
|||||||
return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
|
return hash ? hash.replace(/^#/, "").split(/\//)[0] : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.get_hash_section = function (hash) {
|
||||||
|
// given "#settings/your-account", returns "your-account"
|
||||||
|
// given '#streams/5/social", returns "5"
|
||||||
|
if (!hash) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts = hash.replace(/\/$/, "").split(/\//);
|
||||||
|
|
||||||
|
return parts[1] || '';
|
||||||
|
};
|
||||||
|
|
||||||
// Some browsers zealously URI-decode the contents of
|
// Some browsers zealously URI-decode the contents of
|
||||||
// window.location.hash. So we hide our URI-encoding
|
// window.location.hash. So we hide our URI-encoding
|
||||||
// by replacing % with . (like MediaWiki).
|
// by replacing % with . (like MediaWiki).
|
||||||
|
|||||||
Reference in New Issue
Block a user