From d2df4c840c134ba63710b0697e0c08405f3dcedb Mon Sep 17 00:00:00 2001 From: MacKenzie Date: Wed, 20 Apr 2016 08:40:48 -0700 Subject: [PATCH] Updated fix for #205 to address underlying problem --- src/ui-layout.js | 10 ++++-- test/uiLayoutCtrl.spec.js | 65 +++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/ui-layout.js b/src/ui-layout.js index c8776e7..ee93765 100644 --- a/src/ui-layout.js +++ b/src/ui-layout.js @@ -171,13 +171,17 @@ angular.module('ui.layout', []) return event; }; - ctrl.mouseMoveHandler = function(mouseEvent) { - - var mousePos = ctrl.sizeProperties.mouseProperty in mouseEvent ? mouseEvent[ctrl.sizeProperties.mouseProperty] + ctrl.getMousePosition = function(mouseEvent){ + return 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; + }; + + ctrl.mouseMoveHandler = function(mouseEvent) { + + var mousePos = ctrl.getMousePosition(mouseEvent); if(mousePos === null) return; diff --git a/test/uiLayoutCtrl.spec.js b/test/uiLayoutCtrl.spec.js index 1839fbc..78d25d8 100644 --- a/test/uiLayoutCtrl.spec.js +++ b/test/uiLayoutCtrl.spec.js @@ -37,67 +37,60 @@ describe('Controller: uiLayoutCtrl', function () { expect(uic.isLayoutElement(notUiEl)).toEqual(false); }); - describe('mouseMoveHandler', function(){ + describe('getMousePosition', function(){ - var controller, jQueryWindow; + var controller; beforeEach(function(){ - - jQueryWindow = {}; - - spyOn(window, 'requestAnimationFrame'); - controller = $controller('uiLayoutCtrl', { $scope: scope, $attrs: {}, - $element: angular.element('
'), - $window: jQueryWindow - }); + $element: angular.element('
')}); }); - it('should handle standard mouse event without exception', function(){ + it('should handle standard mouse event', function(){ var mockMouseEvent = {}; mockMouseEvent[controller.sizeProperties.mouseProperty] = 0; - controller.mouseMoveHandler(mockMouseEvent); + var result = controller.getMousePosition(mockMouseEvent); - expect(window.requestAnimationFrame).toHaveBeenCalled(); + expect(result).toEqual(0); }); - it('should handle jQuery mouse event without exception', function(){ + it('should handle jQuery mouse event', function(){ + var mockMouseEvent = { originalEvent: {} }; mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0; - controller.mouseMoveHandler(mockMouseEvent); - - expect(window.requestAnimationFrame).toHaveBeenCalled(); + var result = controller.getMousePosition(mockMouseEvent); + + expect(result).toEqual(0); }); - it('should handle standard touch event without exception', function(){ + it('should handle standard touch event', function(){ + var mockMouseEvent = { targetTouches: [] }; mockMouseEvent.targetTouches[0] = {}; mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; - controller.mouseMoveHandler(mockMouseEvent); - - expect(window.requestAnimationFrame).toHaveBeenCalled(); + var result = controller.getMousePosition(mockMouseEvent); + + expect(result).toEqual(0); }); - it('should handle unrecognised standard event without exception', function(){ + it('should handle unrecognised standard event', function(){ var mockMouseEvent = {}; - controller.mouseMoveHandler(mockMouseEvent); + var result = controller.getMousePosition(mockMouseEvent); - expect(window.requestAnimationFrame).not.toHaveBeenCalled(); + expect(result).toEqual(null); }); - it('should handle jQuery touch event without exception', function(){ - - jQueryWindow.jQuery = true; + it('should handle jQuery touch event', function(){ var mockMouseEvent = { originalEvent: { @@ -108,22 +101,20 @@ describe('Controller: uiLayoutCtrl', function () { mockMouseEvent.originalEvent.targetTouches[0] = {}; mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; - controller.mouseMoveHandler(mockMouseEvent); - - expect(window.requestAnimationFrame).toHaveBeenCalled(); + var result = controller.getMousePosition(mockMouseEvent); + + expect(result).toEqual(0); }); - it('should handle unrecognised jQuery event without exception', function(){ - - jQueryWindow.jQuery = true; - + it('should handle unrecognised jQuery event', function(){ + var mockMouseEvent = { originalEvent: {} }; - controller.mouseMoveHandler(mockMouseEvent); - - expect(window.requestAnimationFrame).not.toHaveBeenCalled(); + var result = controller.getMousePosition(mockMouseEvent); + + expect(result).toEqual(null); }); }); });