diff --git a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js index b1a95fee7c..19b9061be6 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js @@ -12,7 +12,8 @@ function appState($rootScope) { // changed, we only expose methods to interact with the values. var globalState = { - showNavigation: null + showNavigation: null, + touchDevice: null }; var sectionState = { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js index 4c918da849..e878f54269 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js @@ -29,7 +29,7 @@ */ angular.module('umbraco.services') -.factory('dialogService', function ($rootScope, $compile, $http, $timeout, $q, $templateCache, $log) { +.factory('dialogService', function ($rootScope, $compile, $http, $timeout, $q, $templateCache, appState) { var dialogs = []; @@ -159,7 +159,7 @@ angular.module('umbraco.services') }; scope.swipeHide = function(e){ - if($rootScope.touchDevice){ + if(appState.getGlobalState("touchDevice")){ var selection = window.getSelection(); if(selection.type !== "Range"){ scope.hide(); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js index f64e16b262..34b79b7669 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js @@ -103,7 +103,6 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo var service = { active: false, - touchDevice: false, userDialog: undefined, ui: ui, @@ -385,7 +384,7 @@ function navigationService($rootScope, $routeParams, $log, $location, $q, $timeo return; } - if (!service.touchDevice) { + if (!appState.getGlobalState("touchDevice")) { service.active = false; $timeout(function() { if (!service.active) { diff --git a/src/Umbraco.Web.UI.Client/src/init.js b/src/Umbraco.Web.UI.Client/src/init.js index 78aab7383b..7ecc722acd 100644 --- a/src/Umbraco.Web.UI.Client/src/init.js +++ b/src/Umbraco.Web.UI.Client/src/init.js @@ -1,29 +1,34 @@ /** Executed when the application starts */ -app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', function (userService, $log, $rootScope, $location, navigationService) { +app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', 'appState', + function(userService, $log, $rootScope, $location, navigationService, appState) { - var firstRun = true; + var firstRun = true; - /** when we have a successful first route that is not the login page - meaning the user is authenticated - we'll get the current user from the user service and ensure it broadcasts it's events. If the route - is successful from after a login then this will not actually do anything since the authenticated event would - have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated - then this is when the authenticated event will be fired. - */ - $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { - if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { - firstRun = false; - userService.getCurrentUser({ broadcastEvent: true }); - } - }); + /** when we have a successful first route that is not the login page - meaning the user is authenticated + we'll get the current user from the user service and ensure it broadcasts it's events. If the route + is successful from after a login then this will not actually do anything since the authenticated event would + have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated + then this is when the authenticated event will be fired. + */ + $rootScope.$on('$routeChangeSuccess', function(event, current, previous) { + if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { + firstRun = false; + userService.getCurrentUser({ broadcastEvent: true }); + } + }); - /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including - wiring up it's controller, etc... and then redirect to the rejected URL. */ - $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { - event.preventDefault(); - $location.path(rejection.path).search(rejection.search); - }); + /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including + wiring up it's controller, etc... and then redirect to the rejected URL. */ + $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { + event.preventDefault(); + $location.path(rejection.path).search(rejection.search); + }); - /* this will initialize the navigation service once the application has started */ - navigationService.init(); + /* this will initialize the navigation service once the application has started */ + navigationService.init(); -}]); + //check for touch device, add to global appState + var touchDevice = ("ontouchstart" in window || window.touch || window.navigator.msMaxTouchPoints === 5 || window.DocumentTouch && document instanceof DocumentTouch); + appState.setGlobalState("touchDevice", touchDevice); + + }]); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js index e13c379aa1..81d224294a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js @@ -12,11 +12,6 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ var legacyTreeJsLoaded = false; - //detect if the current device is touch-enabled - //todo, move this out of the controller - $rootScope.touchDevice = ("ontouchstart" in window || window.touch || window.navigator.msMaxTouchPoints===5 || window.DocumentTouch && document instanceof DocumentTouch); - navigationService.touchDevice = $rootScope.touchDevice; - //the null is important because we do an explicit bool check on this in the view //the avatar is by default the umbraco logo $scope.authenticated = null; diff --git a/src/Umbraco.Web.UI/umbraco/js/init.js b/src/Umbraco.Web.UI/umbraco/js/init.js index 78aab7383b..7ecc722acd 100644 --- a/src/Umbraco.Web.UI/umbraco/js/init.js +++ b/src/Umbraco.Web.UI/umbraco/js/init.js @@ -1,29 +1,34 @@ /** Executed when the application starts */ -app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', function (userService, $log, $rootScope, $location, navigationService) { +app.run(['userService', '$log', '$rootScope', '$location', 'navigationService', 'appState', + function(userService, $log, $rootScope, $location, navigationService, appState) { - var firstRun = true; + var firstRun = true; - /** when we have a successful first route that is not the login page - meaning the user is authenticated - we'll get the current user from the user service and ensure it broadcasts it's events. If the route - is successful from after a login then this will not actually do anything since the authenticated event would - have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated - then this is when the authenticated event will be fired. - */ - $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { - if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { - firstRun = false; - userService.getCurrentUser({ broadcastEvent: true }); - } - }); + /** when we have a successful first route that is not the login page - meaning the user is authenticated + we'll get the current user from the user service and ensure it broadcasts it's events. If the route + is successful from after a login then this will not actually do anything since the authenticated event would + have alraedy fired, but if the user is loading the angularjs app for the first time and they are already authenticated + then this is when the authenticated event will be fired. + */ + $rootScope.$on('$routeChangeSuccess', function(event, current, previous) { + if (firstRun && !$location.url().toLowerCase().startsWith("/login")) { + firstRun = false; + userService.getCurrentUser({ broadcastEvent: true }); + } + }); - /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including - wiring up it's controller, etc... and then redirect to the rejected URL. */ - $rootScope.$on('$routeChangeError', function (event, current, previous, rejection) { - event.preventDefault(); - $location.path(rejection.path).search(rejection.search); - }); + /** When the route change is rejected - based on checkAuth - we'll prevent the rejected route from executing including + wiring up it's controller, etc... and then redirect to the rejected URL. */ + $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { + event.preventDefault(); + $location.path(rejection.path).search(rejection.search); + }); - /* this will initialize the navigation service once the application has started */ - navigationService.init(); + /* this will initialize the navigation service once the application has started */ + navigationService.init(); -}]); + //check for touch device, add to global appState + var touchDevice = ("ontouchstart" in window || window.touch || window.navigator.msMaxTouchPoints === 5 || window.DocumentTouch && document instanceof DocumentTouch); + appState.setGlobalState("touchDevice", touchDevice); + + }]); \ No newline at end of file