Skip to content

Commit

Permalink
fix: update history when closing Reveal with replaceState foundatio…
Browse files Browse the repository at this point in the history
…n#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 foundation#8012
  • Loading branch information
ncoden committed Mar 26, 2018
1 parent e3e7e9c commit 42d267a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions js/foundation.reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 42d267a

Please sign in to comment.