diff --git a/src/ui-layout.js b/src/ui-layout.js index 223b591..d0e79c6 100644 --- a/src/ui-layout.js +++ b/src/ui-layout.js @@ -176,7 +176,7 @@ angular.module('ui.layout', []) (mouseEvent.originalEvent && mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty]) || // jQuery does touches weird, see #82 ($window.jQuery ? - (mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) : + (mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) : (mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0)); lastPos = mousePos - offset($element)[ctrl.sizeProperties.offsetPos]; diff --git a/test/uiLayoutCtrl.spec.js b/test/uiLayoutCtrl.spec.js index deb9f38..b005f0f 100644 --- a/test/uiLayoutCtrl.spec.js +++ b/test/uiLayoutCtrl.spec.js @@ -36,5 +36,81 @@ describe('Controller: uiLayoutCtrl', function () { expect(uic.isLayoutElement(tagContainer)).toEqual(true); expect(uic.isLayoutElement(notUiEl)).toEqual(false); }); + + describe('mouseMoveHandler', function(){ + + var controller, window; + + beforeEach(function(){ + + window = {}; + + controller = $controller('uiLayoutCtrl', { + $scope: scope, + $attrs: {}, + $element: angular.element('
'), + $window: window + }); + }); + + it('should handle standard mouse event without exception', function(){ + var mockMouseEvent = {}; + mockMouseEvent[controller.sizeProperties.mouseProperty] = 0; + + controller.mouseMoveHandler(mockMouseEvent); + }); + + it('should handle jQuery mouse event without exception', function(){ + var mockMouseEvent = { + originalEvent: {} + }; + mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0; + + controller.mouseMoveHandler(mockMouseEvent); + }); + + it('should handle standard touch event without exception', function(){ + var mockMouseEvent = { + targetTouches: [] + }; + mockMouseEvent.targetTouches[0] = {}; + mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; + + controller.mouseMoveHandler(mockMouseEvent); + }); + + it('should handle unrecognised standard event without exception', function(){ + var mockMouseEvent = {}; + + controller.mouseMoveHandler(mockMouseEvent); + }); + + it('should handle jQuery touch event without exception', function(){ + + window.jQuery = true; + + var mockMouseEvent = { + originalEvent: { + targetTouches: [] + } + }; + + mockMouseEvent.originalEvent.targetTouches[0] = {}; + mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0; + + controller.mouseMoveHandler(mockMouseEvent); + }); + + it('should handle unrecognised jQuery event without exception', function(){ + + window.jQuery = true; + + var mockMouseEvent = { + originalEvent: {} + }; + + controller.mouseMoveHandler(mockMouseEvent); + }); + }); }); }); \ No newline at end of file