mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 04:08:22 +00:00
[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:
@ -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,
|
// If this is the first active instance of this directive,
|
||||||
// register as the window's beforeunload handler
|
// register as the window's beforeunload handler
|
||||||
if (unloads.length === 0) {
|
if (unloads.length === 0) {
|
||||||
@ -54,6 +65,9 @@ define(
|
|||||||
|
|
||||||
// Remove it when the scope is destroyed
|
// Remove it when the scope is destroyed
|
||||||
scope.$on("$destroy", removeUnload);
|
scope.$on("$destroy", removeUnload);
|
||||||
|
|
||||||
|
// Also handle route changes
|
||||||
|
scope.$on("$locationChangeStart", checkLocationChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user