diff --git a/platform/commonUI/edit/src/controllers/EditController.js b/platform/commonUI/edit/src/controllers/EditController.js index d491c448fa..1c3ebe7e8f 100644 --- a/platform/commonUI/edit/src/controllers/EditController.js +++ b/platform/commonUI/edit/src/controllers/EditController.js @@ -31,9 +31,19 @@ define( }); return { + /** + * Get the domain object which is navigated-to. + * @returns {DomainObject} the domain object that is navigated-to + */ navigatedObject: function () { return navigatedObject; }, + /** + * Get the warning to show if the user attempts to navigate + * away from Edit mode while unsaved changes are present. + * @returns {string} the warning to show, or undefined if + * there are no unsaved changes + */ getUnloadWarning: function () { var editorCapability = navigatedObject && navigatedObject.getCapability("editor"), diff --git a/platform/commonUI/edit/src/directives/MCTBeforeUnload.js b/platform/commonUI/edit/src/directives/MCTBeforeUnload.js index 10ced76db3..92309eb0c1 100644 --- a/platform/commonUI/edit/src/directives/MCTBeforeUnload.js +++ b/platform/commonUI/edit/src/directives/MCTBeforeUnload.js @@ -43,12 +43,14 @@ define( } } - // Include this instance of the directive's unload function - unloads.push(unload); - // If this is the first active instance of this directive, // register as the window's beforeunload handler - $window.onbeforeunload = checkUnloads; + if (unloads.length === 0) { + $window.onbeforeunload = checkUnloads; + } + + // Include this instance of the directive's unload function + unloads.push(unload); // Remove it when the scope is destroyed scope.$on("$destroy", removeUnload);