Skip to content

Commit

Permalink
Fixed mouseMoveHandler to handle mouse position of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzieajudd committed Apr 20, 2016
1 parent 19fa58b commit e151379
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 5 additions & 5 deletions test/uiLayoutCtrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -123,7 +123,7 @@ describe('Controller: uiLayoutCtrl', function () {

controller.mouseMoveHandler(mockMouseEvent);

expect(window.requestAnimationFrame).toHaveBeenCalled();
expect(window.requestAnimationFrame).not.toHaveBeenCalled();
});
});
});
Expand Down

0 comments on commit e151379

Please sign in to comment.