[Edit] Check for route changes

Respond to route changes via mct-before-unload, in order to
show a prompt to allow the user to confirm navigation changes
which do not trigger onbeforeunload (such as using back to
change the hash route). WTD-1035.
This commit is contained in:
Victor Woeltjen 2015-03-31 14:46:11 -07:00
parent 5ef382d159
commit dc7d504691

View File

@ -43,6 +43,17 @@ define(
}
}
// Show a dialog before allowing a location change
function checkLocationChange(event) {
// Get an unload message (if any)
var warning = unload();
// Prompt the user if there's an unload message
if (warning && !$window.confirm(warning)) {
// ...and prevent the route change if it was confirmed
event.preventDefault();
}
}
// If this is the first active instance of this directive,
// register as the window's beforeunload handler
if (unloads.length === 0) {
@ -54,6 +65,9 @@ define(
// Remove it when the scope is destroyed
scope.$on("$destroy", removeUnload);
// Also handle route changes
scope.$on("$locationChangeStart", checkLocationChange);
}
return {