Skip to content

Commit

Permalink
Updated fix for angular-ui#205 to address underlying problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzieajudd committed Apr 20, 2016
1 parent e151379 commit d2df4c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
10 changes: 7 additions & 3 deletions src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
65 changes: 28 additions & 37 deletions test/uiLayoutCtrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div></div>'),
$window: jQueryWindow
});
$element: angular.element('<div></div>')});
});

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: {
Expand All @@ -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);
});
});
});
Expand Down

0 comments on commit d2df4c8

Please sign in to comment.