Skip to content

Commit b28adb6

Browse files
Added fix and tests for angular-ui#205
1 parent 5e23ee9 commit b28adb6

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

Diff for: src/ui-layout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ 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[0][ctrl.sizeProperties.mouseProperty] : 0) :
179+
(mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) :
180180
(mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0));
181181

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

Diff for: test/uiLayoutCtrl.spec.js

+76
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,81 @@ describe('Controller: uiLayoutCtrl', function () {
3636
expect(uic.isLayoutElement(tagContainer)).toEqual(true);
3737
expect(uic.isLayoutElement(notUiEl)).toEqual(false);
3838
});
39+
40+
describe('mouseMoveHandler', function(){
41+
42+
var controller, window;
43+
44+
beforeEach(function(){
45+
46+
window = {};
47+
48+
controller = $controller('uiLayoutCtrl', {
49+
$scope: scope,
50+
$attrs: {},
51+
$element: angular.element('<div></div>'),
52+
$window: window
53+
});
54+
});
55+
56+
it('should handle standard mouse event without exception', function(){
57+
var mockMouseEvent = {};
58+
mockMouseEvent[controller.sizeProperties.mouseProperty] = 0;
59+
60+
controller.mouseMoveHandler(mockMouseEvent);
61+
});
62+
63+
it('should handle jQuery mouse event without exception', function(){
64+
var mockMouseEvent = {
65+
originalEvent: {}
66+
};
67+
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0;
68+
69+
controller.mouseMoveHandler(mockMouseEvent);
70+
});
71+
72+
it('should handle standard touch event without exception', function(){
73+
var mockMouseEvent = {
74+
targetTouches: []
75+
};
76+
mockMouseEvent.targetTouches[0] = {};
77+
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
78+
79+
controller.mouseMoveHandler(mockMouseEvent);
80+
});
81+
82+
it('should handle unrecognised standard event without exception', function(){
83+
var mockMouseEvent = {};
84+
85+
controller.mouseMoveHandler(mockMouseEvent);
86+
});
87+
88+
it('should handle jQuery touch event without exception', function(){
89+
90+
window.jQuery = true;
91+
92+
var mockMouseEvent = {
93+
originalEvent: {
94+
targetTouches: []
95+
}
96+
};
97+
98+
mockMouseEvent.originalEvent.targetTouches[0] = {};
99+
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;
100+
101+
controller.mouseMoveHandler(mockMouseEvent);
102+
});
103+
104+
it('should handle unrecognised jQuery event without exception', function(){
105+
106+
window.jQuery = true;
107+
108+
var mockMouseEvent = {
109+
originalEvent: {}
110+
};
111+
112+
controller.mouseMoveHandler(mockMouseEvent);
113+
});
114+
});
39115
});
40116
});

0 commit comments

Comments
 (0)