Skip to content

Instantly share code, notes, and snippets.

@alecguintu
Created September 4, 2014 10:18
Show Gist options
  • Save alecguintu/9d54e4ba88a2e9e2ad8d to your computer and use it in GitHub Desktop.
Save alecguintu/9d54e4ba88a2e9e2ad8d to your computer and use it in GitHub Desktop.
Adding page:before-change for turbolinks
if (!settings.silent && !window.aysUnloadSet) {
window.aysUnloadSet = true;
$(window).bind('beforeunload', function() {
$dirtyForms = $("form").filter('.' + settings.dirtyClass);
if ($dirtyForms.length == 0) {
return;
}
// Prevent multiple prompts - seen on Chrome and IE
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
if (window.aysHasPrompted) {
return;
}
window.aysHasPrompted = true;
window.setTimeout(function() {window.aysHasPrompted = false;}, 900);
}
return settings.message;
});
$(document).bind('page:before-change', function() {
$dirtyForms = $("form").filter('.' + settings.dirtyClass);
if ($dirtyForms.length == 0) {
return;
}
// Prevent multiple prompts - seen on Chrome and IE
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
if (window.aysHasPrompted) {
return;
}
window.aysHasPrompted = true;
window.setTimeout(function() {window.aysHasPrompted = false;}, 900);
}
return confirm(settings.message + "\n\nAre you sure you want to leave this page?");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment