mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Use pushState where supported to change the URL hash
This this removed one forced relayout of the page on unnarrow. This saves about 100ms for me. (imported from commit 0755f425abbe3d99b8a99765549a5bbf3c620b9a)
This commit is contained in:
@@ -19,13 +19,23 @@ function decodeHashComponent(str) {
|
||||
return decodeURIComponent(str.replace(/\./g, '%'));
|
||||
}
|
||||
|
||||
function set_hash(hash) {
|
||||
if (history.pushState) {
|
||||
console.log(window.location);
|
||||
// Build a full URL to not have same origin problems
|
||||
var url = window.location.origin + window.location.pathname + hash;
|
||||
history.pushState(null, null, url);
|
||||
} else {
|
||||
window.location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
||||
exports.changehash = function (newhash) {
|
||||
if (changing_hash) {
|
||||
return;
|
||||
}
|
||||
$(document).trigger($.Event('hashchange.zulip'));
|
||||
expected_hash = newhash;
|
||||
window.location.hash = newhash;
|
||||
set_hash(newhash);
|
||||
util.reset_favicon();
|
||||
};
|
||||
|
||||
@@ -115,7 +125,7 @@ function do_hashchange(from_reload) {
|
||||
if (operators === undefined) {
|
||||
// If the narrow URL didn't parse, clear
|
||||
// window.location.hash and send them to the home tab
|
||||
window.location.hash = '';
|
||||
set_hash('');
|
||||
activate_home_tab();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ casper.then(function () {
|
||||
// Test the inline subscribe and unsubscribe in messages
|
||||
casper.then(function () {
|
||||
casper.click('a[href^="#"]');
|
||||
casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/#$/, 'URL suggests we are on home page');
|
||||
casper.test.assertExists('#home.tab-pane.active', 'home page is active');
|
||||
});
|
||||
|
||||
// Test an inline subscribe button for an unsubscribed stream
|
||||
|
||||
Reference in New Issue
Block a user