Addressing issues from code review

This commit is contained in:
Henry
2016-02-29 17:22:13 -08:00
parent 2cc2c6a9d3
commit f192544be3
13 changed files with 147 additions and 98 deletions

View File

@@ -35,7 +35,7 @@ define(
* @constructor
* @param $window the window
*/
function MCTBeforeUnload($window, navigationService) {
function MCTBeforeUnload($window) {
var unloads = [],
oldBeforeUnload = $window.onbeforeunload;
@@ -57,7 +57,6 @@ define(
// Stop using this unload expression
function removeUnload() {
navigationService.removeListener(checkNavigationEvent, "before");
unloads = unloads.filter(function (callback) {
return callback !== unload;
});
@@ -66,28 +65,17 @@ define(
}
}
function shouldAllowNavigation(){
// 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
return !warning || $window.confirm(warning);
}
// Show a dialog before allowing a location change
function checkLocationChange(event) {
if (!shouldAllowNavigation()) {
// Prevent the route change if it was confirmed
if (warning && !$window.confirm(warning)) {
// ...and prevent the route change if it was confirmed
event.preventDefault();
}
}
// Show a dialog before allowing a location change
function checkNavigationEvent(event) {
// Return a false value to the navigationService to
// indicate that the navigation event should be prevented
return shouldAllowNavigation();
}
// If this is the first active instance of this directive,
// register as the window's beforeunload handler
if (unloads.length === 0) {
@@ -102,8 +90,6 @@ define(
// Also handle route changes
scope.$on("$locationChangeStart", checkLocationChange);
navigationService.addListener(checkNavigationEvent, "before");
}
return {