Created
September 4, 2014 10:18
-
-
Save alecguintu/9d54e4ba88a2e9e2ad8d to your computer and use it in GitHub Desktop.
Adding page:before-change for turbolinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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