From 0e9e0e545fc375a27c775fc64d65c9fae4fc58a9 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 27 Jan 2017 14:57:45 +0100 Subject: [PATCH] Load the new pad when the hash is changed --- www/common/cryptpad-common.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index bc4ffb42a..aa180b73a 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -661,8 +661,27 @@ define([ $(function() { // Race condition : if document.body is undefined when alertify.js is loaded, Alertify // won't work. We have to reset it now to make sure it uses a correct "body" - Alertify.reset(); + + // Load the new pad when the hash has changed + var oldHash = document.location.hash.slice(1); + window.onhashchange = function () { + var newHash = document.location.hash.slice(1); + var parsedOld = parseHash(oldHash); + var parsedNew = parseHash(newHash); + if (parsedOld && parsedNew && ( + parsedOld.channel !== parsedNew.channel + || parsedOld.mode !== parsedNew.mode + || parsedOld.key !== parsedNew.key)) { + document.location.reload(); + return; + } + if (parsedNew) { + oldHash = newHash; + } + }; + + // Everything's ready, continue... if($('#pad-iframe').length) { var $iframe = $('#pad-iframe'); var iframe = $iframe[0];