diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index 96f89ee2e0..0aba8fc246 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -182,7 +182,7 @@ define( // and in portrait mode, than, hide the tree menu TreeNodeController.prototype.setObject = function (ngModel, domainObject) { ngModel.selectedObject = domainObject; - if (this.agentService.getOrientation() === "portrait" && + if (this.agentService.getOrientation(window.innerWidth, window.innerHeight) === "portrait" && this.agentService.isPhone(navigator.userAgent)) { this.$scope.$emit('select-obj'); } diff --git a/platform/commonUI/general/src/services/AgentService.js b/platform/commonUI/general/src/services/AgentService.js index fa790e966f..1c7c83c9c3 100644 --- a/platform/commonUI/general/src/services/AgentService.js +++ b/platform/commonUI/general/src/services/AgentService.js @@ -67,11 +67,12 @@ define( } // Returns the orientation of the device based on the - // device's window dimensions - function getOrientation() { - if (window.innerWidth > window.innerHeight) { + // device's window dimensions, pass in the innerWidth + // and innerheight of the current window + function getOrientation(innerWidth, innerHeight) { + if (innerWidth > innerHeight) { return "landscape"; - } else if (window.innerWidth < window.innerHeight) { + } else if (innerWidth < innerHeight) { return "portrait"; } } diff --git a/platform/commonUI/general/test/services/AgentServiceSpec.js b/platform/commonUI/general/test/services/AgentServiceSpec.js index e0f689ddfc..e24cc8e7f7 100644 --- a/platform/commonUI/general/test/services/AgentServiceSpec.js +++ b/platform/commonUI/general/test/services/AgentServiceSpec.js @@ -38,8 +38,8 @@ define( // Creates a mockLocation, used to // do the view search mockWindow = jasmine.createSpyObj( - "$window", - [ "outerWidth", "outerHeight" ] + "window", + [ "innerWidth", "innerHeight" ] ); mockNavigator = jasmine.createSpyObj( @@ -47,7 +47,7 @@ define( [ "userAgent" ] ); - agentService = new AgentService(mockWindow); + agentService = new AgentService(); }); it("get current device user agent", function () { @@ -61,13 +61,8 @@ define( }); it("get orientation of the current device", function () { - mockWindow.outerWidth = 768; - mockWindow.outerHeight = 1024; - agentService.getOrientation(); - - mockWindow.outerWidth = 1024; - mockWindow.outerHeight = 768; - agentService.getOrientation(); + agentService.getOrientation(1024, 768); + agentService.getOrientation(768, 1024); }); }); }