Skip to content

Commit d786ff6

Browse files
committed
Do not hide modal on back button if Turbolinks enabled
There doesn't seem to be any way to prevent Turbolinks from reloading and replacing the entire browser window when a user clicks Back (since turbolinks:before-visit is not triggered for _when navigating by history_), So, rather than hiding the displayed modal when clicking Back (and then having to reload the page), we keep the Modal displayed while Turbolinks does its stuff in the background (including progress bar). See turbolinks/turbolinks#264 for a related issue (suggested `turbolinks:before-history-change` event).
1 parent 00cfc77 commit d786ff6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

jquery.modal.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@
8585
// popstate gets the _after_ state, not the _before_ state
8686
$.modal.handlePopstate = function(event) {
8787
if (event.state.no_modals) {
88-
$.modal.close();
88+
if (typeof Turbolinks != 'undefined' && Turbolinks.supported) {
89+
// do nothing; Turbolinks will be reloading the page anyway, unfortunately,
90+
// so rather than hiding a modal (suggesting the page is ready) and then refreshing
91+
// the page, we keep the modal displayed while the page reloads
92+
} else {
93+
$.modal.close();
94+
}
8995
} else if (event.state.modal) {
9096
elm = $(event.state.modal);
9197
elm.trigger($.modal.REOPEN, event);

0 commit comments

Comments
 (0)