Removes touchDevice from rootScope and navigationService, now we detect this on app startup and add to the globalState which can be retrieved whenever.
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
}]);
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
}]);
|
||||
Reference in New Issue
Block a user