diff --git a/docs/src/guide/index.md b/docs/src/guide/index.md index 1d8a422299..c4d52c9501 100644 --- a/docs/src/guide/index.md +++ b/docs/src/guide/index.md @@ -1338,20 +1338,6 @@ are supported: Open MCT defines several Angular directives that are intended for use both internally within the platform, and by plugins. - -## Before Unload - -The `mct-before-unload` directive is used to listen for (and prompt for user -confirmation) of navigation changes in the browser. This includes reloading, -following links out of Open MCT, or changing routes. It is used to hook into -both `onbeforeunload` event handling as well as route changes from within -Angular. - -This directive is useable as an attribute. Its value should be an Angular -expression. When an action that would trigger an unload and/or route change -occurs, this Angular expression is evaluated. Its result should be a message to -display to the user to confirm their navigation change; if this expression -evaluates to a falsy value, no message will be displayed. ## Chart diff --git a/platform/commonUI/browse/src/navigation/NavigationService.js b/platform/commonUI/browse/src/navigation/NavigationService.js index a3307d5276..0cc520e757 100644 --- a/platform/commonUI/browse/src/navigation/NavigationService.js +++ b/platform/commonUI/browse/src/navigation/NavigationService.js @@ -39,6 +39,9 @@ define( this.callbacks = []; this.checks = []; this.$window = $window; + + this.oldUnload = $window.onbeforeunload; + $window.onbeforeunload = this.onBeforeUnload.bind(this); } /** @@ -173,6 +176,22 @@ define( return false; }; + /** + * Listener for window on before unload event-- will warn before + * navigation is allowed. + * + * @private + */ + NavigationService.prototype.onBeforeUnload = function () { + var shouldWarnBeforeNavigate = this.shouldWarnBeforeNavigate(); + if (shouldWarnBeforeNavigate) { + return shouldWarnBeforeNavigate; + } + if (this.oldUnload) { + return this.oldUnload.apply(undefined, [].slice.apply(arguments)); + } + }; + return NavigationService; } ); diff --git a/platform/commonUI/edit/README.md b/platform/commonUI/edit/README.md index a1e88d330c..ca52b78f1a 100644 --- a/platform/commonUI/edit/README.md +++ b/platform/commonUI/edit/README.md @@ -2,25 +2,6 @@ Contains sources and resources associated with Edit mode. # Extensions -## Directives - -This bundle introduces the `mct-before-unload` directive, primarily for -internal use (to prompt the user to confirm navigation away from unsaved -changes in Edit mode.) - -The `mct-before-unload` directive is used as an attribute whose value is -an Angular expression that is evaluated when navigation changes (either -via browser-level changes, such as the refresh button, or changes to -the Angular route, which happens when hitting the back button in Edit -mode.) The result of this evaluation, when truthy, is shown in a browser -dialog to allow the user to confirm navigation. When falsy, no prompt is -shown, allowing these dialogs to be shown conditionally. (For instance, in -Edit mode, prompts are only shown if user-initiated changes have -occurred.) - -This directive may be attached to any element; its behavior will be enforced -so long as that element remains within the DOM. - # Toolbars Views may specify the contents of a toolbar through a `toolbar` diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index 8b9aad6d21..d60afc9add 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -25,7 +25,6 @@ define([ "./src/controllers/EditPanesController", "./src/controllers/ElementsController", "./src/controllers/EditObjectController", - "./src/directives/MCTBeforeUnload", "./src/actions/EditAndComposeAction", "./src/actions/EditAction", "./src/actions/PropertiesAction", @@ -65,7 +64,6 @@ define([ EditPanesController, ElementsController, EditObjectController, - MCTBeforeUnload, EditAndComposeAction, EditAction, PropertiesAction, @@ -152,15 +150,6 @@ define([ ] } ], - "directives": [ - { - "key": "mctBeforeUnload", - "implementation": MCTBeforeUnload, - "depends": [ - "$window" - ] - } - ], "actions": [ { "key": "compose", diff --git a/platform/commonUI/edit/res/templates/edit-object.html b/platform/commonUI/edit/res/templates/edit-object.html index f93f3cd60f..dcd892c9d3 100644 --- a/platform/commonUI/edit/res/templates/edit-object.html +++ b/platform/commonUI/edit/res/templates/edit-object.html @@ -20,8 +20,7 @@ at runtime from the About dialog for additional information. -->