From 303c65f2c39e945a16b4ad4dc764a2ef6bb50443 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 7 Nov 2016 11:20:30 +0100 Subject: [PATCH 1/2] 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) { From c2770a7a7461a903c1b267025a3d5bb89b882d81 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 7 Nov 2016 15:03:17 +0100 Subject: [PATCH 2/2] set correct hash even if browser does not implement replaceState --- www/code/main.js | 2 +- www/common/cryptpad-common.js | 4 ++-- www/pad/main.js | 2 +- www/poll/main.js | 2 +- www/slide/main.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index a12d4bb8c..da0a2a385 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -495,7 +495,7 @@ define([ } // set the hash - if (!readOnly) { Cryptpad.setHash(editHash); } + if (!readOnly) { Cryptpad.replaceHash(editHash); } Cryptpad.getPadTitle(function (err, title) { if (err) { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 85f07234c..1866fb34a 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -225,9 +225,9 @@ define([ return secret; }; - var setHash = common.setHash = function (hash) { - if (!/^#/.test(hash)) { hash = '#' + hash; } + var replaceHash = common.replaceHash = function (hash) { if (window.history && window.history.replaceState) { + if (!/^#/.test(hash)) { hash = '#' + hash; } return void window.history.replaceState({}, window.document.title, hash); } window.location.hash = hash; diff --git a/www/pad/main.js b/www/pad/main.js index c55370771..d1e6c9df0 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -601,7 +601,7 @@ define([ } // set the hash - if (!readOnly) { Cryptpad.setHash(editHash); } + if (!readOnly) { Cryptpad.replaceHash(editHash); } Cryptpad.getPadTitle(function (err, title) { if (err) { diff --git a/www/poll/main.js b/www/poll/main.js index 1caa10793..9fbf2cfde 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -914,7 +914,7 @@ define([ editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); } // set the hash - if (!readOnly) { Cryptpad.setHash(editHash); } + if (!readOnly) { Cryptpad.replaceHash(editHash); } module.patchText = TextPatcher.create({ realtime: realtime, diff --git a/www/slide/main.js b/www/slide/main.js index 3efb9bd45..a291ae02c 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 === '#') { - Cryptpad.setHash(editHash); + Cryptpad.replaceHash(editHash); } Cryptpad.getPadTitle(function (err, title) {