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

Commit 073e8f9

Browse files
Updated to not requestAnimationFrame if no valide mousePosition found
1 parent b28adb6 commit 073e8f9

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/ui-layout.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ angular.module('ui.layout', [])
176176
(mouseEvent.originalEvent && mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty]) ||
177177
// jQuery does touches weird, see #82
178178
($window.jQuery ?
179-
(mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) :
180-
(mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0));
179+
(mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : null) :
180+
(mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : null));
181181

182+
if(mousePos === null) return;
183+
182184
lastPos = mousePos - offset($element)[ctrl.sizeProperties.offsetPos];
183185

184186
//Cancel previous rAF call

test/uiLayoutCtrl.spec.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,55 +39,65 @@ describe('Controller: uiLayoutCtrl', function () {
3939

4040
describe('mouseMoveHandler', function(){
4141

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

4444
beforeEach(function(){
4545

46-
window = {};
46+
jQueryWindow = {};
47+
48+
spyOn(window, 'requestAnimationFrame');
4749

4850
controller = $controller('uiLayoutCtrl', {
4951
$scope: scope,
5052
$attrs: {},
5153
$element: angular.element('<div></div>'),
52-
$window: window
54+
$window: jQueryWindow
5355
});
5456
});
5557

5658
it('should handle standard mouse event without exception', function(){
5759
var mockMouseEvent = {};
58-
mockMouseEvent[controller.sizeProperties.mouseProperty] = 0;
60+
mockMouseEvent[controller.sizeProperties.mouseProperty] = 1;
5961

6062
controller.mouseMoveHandler(mockMouseEvent);
63+
64+
expect(window.requestAnimationFrame).toHaveBeenCalled();
6165
});
6266

6367
it('should handle jQuery mouse event without exception', function(){
6468
var mockMouseEvent = {
6569
originalEvent: {}
6670
};
67-
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0;
71+
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 1;
6872

6973
controller.mouseMoveHandler(mockMouseEvent);
74+
75+
expect(window.requestAnimationFrame).toHaveBeenCalled();
7076
});
7177

7278
it('should handle standard touch event without exception', function(){
7379
var mockMouseEvent = {
7480
targetTouches: []
7581
};
7682
mockMouseEvent.targetTouches[0] = {};
77-
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
83+
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 1;
7884

7985
controller.mouseMoveHandler(mockMouseEvent);
86+
87+
expect(window.requestAnimationFrame).toHaveBeenCalled();
8088
});
8189

8290
it('should handle unrecognised standard event without exception', function(){
8391
var mockMouseEvent = {};
8492

8593
controller.mouseMoveHandler(mockMouseEvent);
94+
95+
expect(window.requestAnimationFrame).not.toHaveBeenCalled();
8696
});
8797

8898
it('should handle jQuery touch event without exception', function(){
8999

90-
window.jQuery = true;
100+
jQueryWindow.jQuery = true;
91101

92102
var mockMouseEvent = {
93103
originalEvent: {
@@ -96,20 +106,24 @@ describe('Controller: uiLayoutCtrl', function () {
96106
};
97107

98108
mockMouseEvent.originalEvent.targetTouches[0] = {};
99-
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
109+
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 1;
100110

101111
controller.mouseMoveHandler(mockMouseEvent);
112+
113+
expect(window.requestAnimationFrame).toHaveBeenCalled();
102114
});
103115

104116
it('should handle unrecognised jQuery event without exception', function(){
105117

106-
window.jQuery = true;
118+
jQueryWindow.jQuery = true;
107119

108120
var mockMouseEvent = {
109121
originalEvent: {}
110122
};
111123

112124
controller.mouseMoveHandler(mockMouseEvent);
125+
126+
expect(window.requestAnimationFrame).toHaveBeenCalled();
113127
});
114128
});
115129
});

0 commit comments

Comments
 (0)