From 29a2e4664b27804a2e020b85e0351b6fcfa930a7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 15 Nov 2018 10:58:47 +0100 Subject: [PATCH] Remove global close dialog events and add them to each component so we can clean up correctly --- .../application/umbcontextmenu.directive.js | 16 +++++++++++++- .../umbcontextdialog.directive.js | 22 +++++++++++++++++-- .../src/common/services/events.service.js | 1 - .../src/controllers/main.controller.js | 21 ------------------ .../src/controllers/navigation.controller.js | 14 ------------ .../application/umb-contextmenu.html | 2 +- .../application/umb-navigation.html | 2 +- .../umbcontextdialog/umb-context-dialog.html | 2 +- .../Umbraco/Views/Default.cshtml | 2 +- 9 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbcontextmenu.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbcontextmenu.directive.js index 45c5c200cb..8d1420b73e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbcontextmenu.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbcontextmenu.directive.js @@ -1,5 +1,5 @@ angular.module("umbraco.directives") -.directive('umbContextMenu', function (navigationService) { +.directive('umbContextMenu', function (navigationService, keyboardService) { return { scope: { menuDialogTitle: "@", @@ -17,6 +17,20 @@ angular.module("umbraco.directives") scope.executeMenuItem = function (action) { navigationService.executeMenuAction(action, scope.currentNode, scope.currentSection); }; + + scope.outSideClick = function() { + navigationService.hideNavigation(); + }; + + keyboardService.bind("esc", function() { + navigationService.hideNavigation(); + }); + + //ensure to unregister from all events! + scope.$on('$destroy', function () { + keyboardService.unbind("esc"); + }); + } }; }); diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js index 535ba2fbc8..926c59144d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js @@ -1,7 +1,24 @@ (function() { 'use strict'; - function UmbContextDialog() { + function UmbContextDialog(navigationService, keyboardService) { + + function link($scope) { + + $scope.outSideClick = function() { + navigationService.hideNavigation(); + } + + keyboardService.bind("esc", function() { + navigationService.hideNavigation(); + }); + + //ensure to unregister from all events! + $scope.$on('$destroy', function () { + keyboardService.unbind("esc"); + }); + + } var directive = { restrict: 'E', @@ -11,7 +28,8 @@ title: "<", currentNode: "<", view: "<" - } + }, + link: link }; return directive; } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/events.service.js b/src/Umbraco.Web.UI.Client/src/common/services/events.service.js index 5f45a2d3e5..6bab8fda81 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/events.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/events.service.js @@ -6,7 +6,6 @@ app.ready app.authenticated app.notAuthenticated - app.closeDialogs app.ysod app.reInitialize app.userRefresh diff --git a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js index 89c8141805..6f3f0bff52 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -23,27 +23,6 @@ function MainController($scope, $location, appState, treeService, notificationsS notificationsService.remove(index); }; - $scope.closeDialogs = function (event) { - //only close dialogs if non-link and non-buttons are clicked - var el = event.target.nodeName; - var els = ["INPUT", "A", "BUTTON"]; - - if (els.indexOf(el) >= 0) { return; } - - var parents = $(event.target).parents("a,button"); - if (parents.length > 0) { - return; - } - - //SD: I've updated this so that we don't close the dialog when clicking inside of the dialog - var nav = $(event.target).parents("#dialog"); - if (nav.length === 1) { - return; - } - - eventsService.emit("app.closeDialogs", event); - }; - $scope.closeSearch = function() { appState.setSearchState("show", false); }; diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 7c26317cea..2263d095a6 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -147,11 +147,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar navigationService.showSearch(); }); - //trigger dialods with a hotkey: - keyboardService.bind("esc", function () { - eventsService.emit("app.closeDialogs"); - }); - $scope.selectedId = navigationService.currentId; var evts = []; @@ -242,15 +237,6 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar } })); - //This reacts to clicks passed to the body element which emits a global call to close all dialogs - evts.push(eventsService.on("app.closeDialogs", function (event) { - if (appState.getGlobalState("stickyNavigation")) { - navigationService.hideNavigation(); - //TODO: don't know why we need this? - we are inside of an angular event listener. - angularHelper.safeApply($scope); - } - })); - //when a user logs out or timesout evts.push(eventsService.on("app.notAuthenticated", function () { $scope.authenticated = false; diff --git a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-contextmenu.html b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-contextmenu.html index 9d3fa3765d..2e7048eefa 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-contextmenu.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-contextmenu.html @@ -1,4 +1,4 @@ -
+

{{menuDialogTitle}}

diff --git a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html index 8cb687daca..9d1da590ab 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html @@ -27,7 +27,7 @@