From 42d267a293b0dc454002e50d4bc2052a74f23e35 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Mon, 26 Mar 2018 10:08:31 +0200 Subject: [PATCH] fix: update history when closing Reveal with `replaceState` #8012 When closing a Reveal with `replaceState: true`, push a new entry to reset the hash. So going back to the history reopen the modals opened before in reverse order. Closes https://github.com/zurb/foundation-sites/issues/8012 --- js/foundation.reveal.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index f0d87b99e..847d53f53 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -437,13 +437,20 @@ class Reveal extends Plugin { } this.isActive = false; - if (_this.options.deepLink) { - if (window.history.replaceState) { - window.history.replaceState('', document.title, window.location.href.replace(`#${this.id}`, '')); - } else { - window.location.hash = ''; - } - } + // If deepLink and we did not switched to an other modal... + if (_this.options.deepLink && window.location.hash === `#${this.id}`) { + // Remove the history hash + if (window.history.replaceState) { + const urlWithoutHash = window.location.pathname + window.location.search; + if (this.options.updateHistory) { + window.history.pushState({}, '', urlWithoutHash); // remove the hash + } else { + window.history.replaceState('', document.title, urlWithoutHash); + } + } else { + window.location.hash = ''; + } + } this.$activeAnchor.focus(); } -- 2.47.2