From e151379abee957ddbf89c21ce0e78658df43aaef Mon Sep 17 00:00:00 2001 From: MacKenzie Date: Wed, 20 Apr 2016 08:29:43 -0700 Subject: [PATCH] Fixed mouseMoveHandler to handle mouse position of 0 --- src/ui-layout.js | 12 ++++++------ test/uiLayoutCtrl.spec.js | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ui-layout.js b/src/ui-layout.js index 918242d..c8776e7 100644 --- a/src/ui-layout.js +++ b/src/ui-layout.js @@ -172,13 +172,13 @@ angular.module('ui.layout', []) }; ctrl.mouseMoveHandler = function(mouseEvent) { - var mousePos = mouseEvent[ctrl.sizeProperties.mouseProperty] || - (mouseEvent.originalEvent && mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty]) || - // jQuery does touches weird, see #82 - ($window.jQuery ? - (mouseEvent.originalEvent ? (mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty]) : null) : - (mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : null)); + var mousePos = ctrl.sizeProperties.mouseProperty in mouseEvent ? mouseEvent[ctrl.sizeProperties.mouseProperty] + : mouseEvent.originalEvent && ctrl.sizeProperties.mouseProperty in mouseEvent.originalEvent ? mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty] + : mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] + : mouseEvent.originalEvent && mouseEvent.originalEvent.targetTouches ? mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] + : null; + if(mousePos === null) return; lastPos = mousePos - offset($element)[ctrl.sizeProperties.offsetPos]; diff --git a/test/uiLayoutCtrl.spec.js b/test/uiLayoutCtrl.spec.js index ed3329c..1839fbc 100644 --- a/test/uiLayoutCtrl.spec.js +++ b/test/uiLayoutCtrl.spec.js @@ -57,7 +57,7 @@ describe('Controller: uiLayoutCtrl', function () { it('should handle standard mouse event without exception', function(){ var mockMouseEvent = {}; - mockMouseEvent[controller.sizeProperties.mouseProperty] = 1; + mockMouseEvent[controller.sizeProperties.mouseProperty] = 0; controller.mouseMoveHandler(mockMouseEvent); @@ -68,7 +68,7 @@ describe('Controller: uiLayoutCtrl', function () { var mockMouseEvent = { originalEvent: {} }; - mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 1; + mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0; controller.mouseMoveHandler(mockMouseEvent); @@ -80,7 +80,7 @@ describe('Controller: uiLayoutCtrl', function () { targetTouches: [] }; mockMouseEvent.targetTouches[0] = {}; - mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 1; + mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; controller.mouseMoveHandler(mockMouseEvent); @@ -106,7 +106,7 @@ describe('Controller: uiLayoutCtrl', function () { }; mockMouseEvent.originalEvent.targetTouches[0] = {}; - mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 1; + mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; controller.mouseMoveHandler(mockMouseEvent); @@ -123,7 +123,7 @@ describe('Controller: uiLayoutCtrl', function () { controller.mouseMoveHandler(mockMouseEvent); - expect(window.requestAnimationFrame).toHaveBeenCalled(); + expect(window.requestAnimationFrame).not.toHaveBeenCalled(); }); }); });