Skip to content

Commit

Permalink
Do not hide modal on back button if Turbolinks enabled
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
soundasleep committed Aug 7, 2018
1 parent 00cfc77 commit d786ff6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jquery.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@
// popstate gets the _after_ state, not the _before_ state
$.modal.handlePopstate = function(event) {
if (event.state.no_modals) {
$.modal.close();
if (typeof Turbolinks != 'undefined' && Turbolinks.supported) {
// do nothing; Turbolinks will be reloading the page anyway, unfortunately,
// so rather than hiding a modal (suggesting the page is ready) and then refreshing
// the page, we keep the modal displayed while the page reloads
} else {
$.modal.close();
}
} else if (event.state.modal) {
elm = $(event.state.modal);
elm.trigger($.modal.REOPEN, event);
Expand Down

0 comments on commit d786ff6

Please sign in to comment.