Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Fix for #205 #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ angular.module('ui.layout', [])
return event;
};

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 = mouseEvent[ctrl.sizeProperties.mouseProperty] ||
(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.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0));

var mousePos = ctrl.getMousePosition(mouseEvent);

if(mousePos === null) return;

lastPos = mousePos - offset($element)[ctrl.sizeProperties.offsetPos];

//Cancel previous rAF call
Expand Down
81 changes: 81 additions & 0 deletions test/uiLayoutCtrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,86 @@ describe('Controller: uiLayoutCtrl', function () {
expect(uic.isLayoutElement(tagContainer)).toEqual(true);
expect(uic.isLayoutElement(notUiEl)).toEqual(false);
});

describe('getMousePosition', function(){

var controller;

beforeEach(function(){
controller = $controller('uiLayoutCtrl', {
$scope: scope,
$attrs: {},
$element: angular.element('<div></div>')});
});

it('should handle standard mouse event', function(){
var mockMouseEvent = {};
mockMouseEvent[controller.sizeProperties.mouseProperty] = 0;

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(0);
});

it('should handle jQuery mouse event', function(){

var mockMouseEvent = {
originalEvent: {}
};
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0;

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(0);
});

it('should handle standard touch event', function(){

var mockMouseEvent = {
targetTouches: []
};
mockMouseEvent.targetTouches[0] = {};
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(0);
});

it('should handle unrecognised standard event', function(){
var mockMouseEvent = {};

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(null);
});

it('should handle jQuery touch event', function(){

var mockMouseEvent = {
originalEvent: {
targetTouches: []
}
};

mockMouseEvent.originalEvent.targetTouches[0] = {};
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(0);
});

it('should handle unrecognised jQuery event', function(){

var mockMouseEvent = {
originalEvent: {}
};

var result = controller.getMousePosition(mockMouseEvent);

expect(result).toEqual(null);
});
});
});
});