From 303c65f2c39e945a16b4ad4dc764a2ef6bb50443 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 7 Nov 2016 11:20:30 +0100 Subject: [PATCH] use replaceState if available, instead of setting the hash --- www/code/main.js | 4 +--- www/common/cryptpad-common.js | 8 ++++++++ www/pad/main.js | 4 +--- www/poll/main.js | 4 +--- www/slide/main.js | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index ee4fd2f0f..a12d4bb8c 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -495,9 +495,7 @@ define([ } // set the hash - if (!readOnly) { - window.location.hash = editHash; - } + if (!readOnly) { Cryptpad.setHash(editHash); } Cryptpad.getPadTitle(function (err, title) { if (err) { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index d28b1e5e5..85f07234c 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -225,6 +225,14 @@ define([ return secret; }; + var setHash = common.setHash = function (hash) { + if (!/^#/.test(hash)) { hash = '#' + hash; } + if (window.history && window.history.replaceState) { + return void window.history.replaceState({}, window.document.title, hash); + } + window.location.hash = hash; + }; + var storageKey = common.storageKey = 'CryptPad_RECENTPADS'; /* diff --git a/www/pad/main.js b/www/pad/main.js index 310a3d353..c55370771 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -601,9 +601,7 @@ define([ } // set the hash - if (!readOnly) { - window.location.hash = editHash; - } + if (!readOnly) { Cryptpad.setHash(editHash); } Cryptpad.getPadTitle(function (err, title) { if (err) { diff --git a/www/poll/main.js b/www/poll/main.js index ac238e36d..1caa10793 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -914,9 +914,7 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } // set the hash - if (!readOnly) { - window.location.hash = editHash; - } + if (!readOnly) { Cryptpad.setHash(editHash); } module.patchText = TextPatcher.create({ realtime: realtime, diff --git a/www/slide/main.js b/www/slide/main.js index 91a174d0f..3efb9bd45 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -585,7 +585,7 @@ define([ // set the hash if (!window.location.hash || window.location.hash === '#') { - window.location.hash = editHash; + Cryptpad.setHash(editHash); } Cryptpad.getPadTitle(function (err, title) {