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:
Jason Michalski
2014-01-29 16:14:00 -05:00
parent fcb8c106b1
commit bd9cccffce
2 changed files with 14 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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