diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbsearch.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbsearch.directive.js index 30551bff09..91eb077ba3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbsearch.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbsearch.directive.js @@ -27,7 +27,7 @@ vm.focusSearch = focusSearch; //we need to capture the focus before this element is initialized. - vm.focusBeforeOpening = focusService.lastKnownFocus; + vm.focusBeforeOpening = focusService.getLastKnownFocus(); function onInit() { vm.searchQuery = ""; diff --git a/src/Umbraco.Web.UI.Client/src/common/services/focus.service.js b/src/Umbraco.Web.UI.Client/src/common/services/focus.service.js index da381a6cc4..ebaff7eb89 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/focus.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/focus.service.js @@ -13,14 +13,17 @@ function focusService() { + var currentFocus = null; + var lastKnownFocus = null; + + function focusInApp(e) { - service.currentFocus = e.target; + currentFocus = e.target; } document.addEventListener('focusin', focusInApp); var service = { - currentFocus: null, /** * @ngdoc property @@ -32,7 +35,9 @@ * This variable is avaiable for directives that are not able to figure out the focused element on init, and there this service will help remembering it untill the directive is initialized. * */ - lastKnownFocus: null, + getLastKnownFocus: function() { + return lastKnownFocus; + }, /** * @ngdoc function @@ -45,7 +50,7 @@ * */ rememberFocus: function() { - service.lastKnownFocus = service.currentFocus; + lastKnownFocus = currentFocus; }, /** @@ -59,7 +64,7 @@ * */ setLastKnownFocus: function(element) { - service.lastKnownFocus = element; + lastKnownFocus = element; } };