Skip to content

Commit 9e942f8

Browse files
Emanuel Klugeajoslin
Emanuel Kluge
authored andcommitted
fix(ionicScrollDelegate): do not error if no scrollTop/Left values
Closes #659
1 parent 465ea76 commit 9e942f8

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

js/ext/angular/src/service/delegates/ionicScrollDelegate.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ angular.module('ionic.ui.service.scrollDelegate', [])
7373
});
7474
}
7575

76-
$element.bind('scroll', function(e) {
76+
$element.on('scroll', function(e) {
77+
if ( !$scope.onScroll ) {
78+
return;
79+
}
80+
var detail = (e.originalEvent || e).detail || {};
81+
7782
$scope.onScroll && $scope.onScroll({
7883
event: e,
79-
scrollTop: e.detail ? e.detail.scrollTop : e.originalEvent ? e.originalEvent.detail.scrollTop : 0,
80-
scrollLeft: e.detail ? e.detail.scrollLeft: e.originalEvent ? e.originalEvent.detail.scrollLeft : 0
84+
scrollTop: detail.scrollTop || 0,
85+
scrollLeft: detail.scrollLeft || 0
8186
});
87+
8288
});
8389

8490
$scope.$parent.$on('scroll.resize', scrollViewResize);

js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js

+20
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ describe('Ionic ScrollDelegate Service', function() {
3131
expect(sv.resize).toHaveBeenCalled();
3232
});
3333

34+
it('scroll event', function() {
35+
var scope = rootScope.$new();
36+
var el = compile('<ion-content></ion-content>')(scope);
37+
scope = el.isolateScope();
38+
scope.$apply();
39+
var top, left;
40+
scope.onScroll = jasmine.createSpy('scroll').andCallFake(function(data) {
41+
top = data.scrollTop;
42+
left = data.scrollLeft;
43+
});
44+
ionic.trigger('scroll', {target: el[0]});
45+
expect(scope.onScroll).toHaveBeenCalled();
46+
expect(top).toBe(0);
47+
expect(left).toBe(0);
48+
49+
ionic.trigger('scroll', {target: el[0], scrollTop: 3, scrollLeft: 4});
50+
expect(top).toBe(3);
51+
expect(left).toBe(4);
52+
});
53+
3454
testWithAnimate(true);
3555
testWithAnimate(false);
3656
function testWithAnimate(animate) {

0 commit comments

Comments
 (0)