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

Commit d2df4c8

Browse files
Updated fix for #205 to address underlying problem
1 parent e151379 commit d2df4c8

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/ui-layout.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,17 @@ angular.module('ui.layout', [])
171171
return event;
172172
};
173173

174-
ctrl.mouseMoveHandler = function(mouseEvent) {
175-
176-
var mousePos = ctrl.sizeProperties.mouseProperty in mouseEvent ? mouseEvent[ctrl.sizeProperties.mouseProperty]
174+
ctrl.getMousePosition = function(mouseEvent){
175+
return ctrl.sizeProperties.mouseProperty in mouseEvent ? mouseEvent[ctrl.sizeProperties.mouseProperty]
177176
: mouseEvent.originalEvent && ctrl.sizeProperties.mouseProperty in mouseEvent.originalEvent ? mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty]
178177
: mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty]
179178
: mouseEvent.originalEvent && mouseEvent.originalEvent.targetTouches ? mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty]
180179
: null;
180+
};
181+
182+
ctrl.mouseMoveHandler = function(mouseEvent) {
183+
184+
var mousePos = ctrl.getMousePosition(mouseEvent);
181185

182186
if(mousePos === null) return;
183187

test/uiLayoutCtrl.spec.js

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,67 +37,60 @@ describe('Controller: uiLayoutCtrl', function () {
3737
expect(uic.isLayoutElement(notUiEl)).toEqual(false);
3838
});
3939

40-
describe('mouseMoveHandler', function(){
40+
describe('getMousePosition', function(){
4141

42-
var controller, jQueryWindow;
42+
var controller;
4343

4444
beforeEach(function(){
45-
46-
jQueryWindow = {};
47-
48-
spyOn(window, 'requestAnimationFrame');
49-
5045
controller = $controller('uiLayoutCtrl', {
5146
$scope: scope,
5247
$attrs: {},
53-
$element: angular.element('<div></div>'),
54-
$window: jQueryWindow
55-
});
48+
$element: angular.element('<div></div>')});
5649
});
5750

58-
it('should handle standard mouse event without exception', function(){
51+
it('should handle standard mouse event', function(){
5952
var mockMouseEvent = {};
6053
mockMouseEvent[controller.sizeProperties.mouseProperty] = 0;
6154

62-
controller.mouseMoveHandler(mockMouseEvent);
55+
var result = controller.getMousePosition(mockMouseEvent);
6356

64-
expect(window.requestAnimationFrame).toHaveBeenCalled();
57+
expect(result).toEqual(0);
6558
});
6659

67-
it('should handle jQuery mouse event without exception', function(){
60+
it('should handle jQuery mouse event', function(){
61+
6862
var mockMouseEvent = {
6963
originalEvent: {}
7064
};
7165
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0;
7266

73-
controller.mouseMoveHandler(mockMouseEvent);
74-
75-
expect(window.requestAnimationFrame).toHaveBeenCalled();
67+
var result = controller.getMousePosition(mockMouseEvent);
68+
69+
expect(result).toEqual(0);
7670
});
7771

78-
it('should handle standard touch event without exception', function(){
72+
it('should handle standard touch event', function(){
73+
7974
var mockMouseEvent = {
8075
targetTouches: []
8176
};
8277
mockMouseEvent.targetTouches[0] = {};
8378
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
8479

85-
controller.mouseMoveHandler(mockMouseEvent);
86-
87-
expect(window.requestAnimationFrame).toHaveBeenCalled();
80+
var result = controller.getMousePosition(mockMouseEvent);
81+
82+
expect(result).toEqual(0);
8883
});
8984

90-
it('should handle unrecognised standard event without exception', function(){
85+
it('should handle unrecognised standard event', function(){
9186
var mockMouseEvent = {};
9287

93-
controller.mouseMoveHandler(mockMouseEvent);
88+
var result = controller.getMousePosition(mockMouseEvent);
9489

95-
expect(window.requestAnimationFrame).not.toHaveBeenCalled();
90+
expect(result).toEqual(null);
9691
});
9792

98-
it('should handle jQuery touch event without exception', function(){
99-
100-
jQueryWindow.jQuery = true;
93+
it('should handle jQuery touch event', function(){
10194

10295
var mockMouseEvent = {
10396
originalEvent: {
@@ -108,22 +101,20 @@ describe('Controller: uiLayoutCtrl', function () {
108101
mockMouseEvent.originalEvent.targetTouches[0] = {};
109102
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
110103

111-
controller.mouseMoveHandler(mockMouseEvent);
112-
113-
expect(window.requestAnimationFrame).toHaveBeenCalled();
104+
var result = controller.getMousePosition(mockMouseEvent);
105+
106+
expect(result).toEqual(0);
114107
});
115108

116-
it('should handle unrecognised jQuery event without exception', function(){
117-
118-
jQueryWindow.jQuery = true;
119-
109+
it('should handle unrecognised jQuery event', function(){
110+
120111
var mockMouseEvent = {
121112
originalEvent: {}
122113
};
123114

124-
controller.mouseMoveHandler(mockMouseEvent);
125-
126-
expect(window.requestAnimationFrame).not.toHaveBeenCalled();
115+
var result = controller.getMousePosition(mockMouseEvent);
116+
117+
expect(result).toEqual(null);
127118
});
128119
});
129120
});

0 commit comments

Comments
 (0)