Skip to content

Commit

Permalink
fix(ionicScrollDelegate): do not error if no scrollTop/Left values
Browse files Browse the repository at this point in the history
Closes #659
  • Loading branch information
Emanuel Kluge authored and ajoslin committed Feb 21, 2014
1 parent 465ea76 commit 9e942f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions js/ext/angular/src/service/delegates/ionicScrollDelegate.js
Expand Up @@ -73,12 +73,18 @@ angular.module('ionic.ui.service.scrollDelegate', [])
});
}

$element.bind('scroll', function(e) {
$element.on('scroll', function(e) {
if ( !$scope.onScroll ) {
return;
}
var detail = (e.originalEvent || e).detail || {};

$scope.onScroll && $scope.onScroll({
event: e,
scrollTop: e.detail ? e.detail.scrollTop : e.originalEvent ? e.originalEvent.detail.scrollTop : 0,
scrollLeft: e.detail ? e.detail.scrollLeft: e.originalEvent ? e.originalEvent.detail.scrollLeft : 0
scrollTop: detail.scrollTop || 0,
scrollLeft: detail.scrollLeft || 0
});

});

$scope.$parent.$on('scroll.resize', scrollViewResize);
Expand Down
20 changes: 20 additions & 0 deletions js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js
Expand Up @@ -31,6 +31,26 @@ describe('Ionic ScrollDelegate Service', function() {
expect(sv.resize).toHaveBeenCalled();
});

it('scroll event', function() {
var scope = rootScope.$new();
var el = compile('<ion-content></ion-content>')(scope);
scope = el.isolateScope();
scope.$apply();
var top, left;
scope.onScroll = jasmine.createSpy('scroll').andCallFake(function(data) {
top = data.scrollTop;
left = data.scrollLeft;
});
ionic.trigger('scroll', {target: el[0]});
expect(scope.onScroll).toHaveBeenCalled();
expect(top).toBe(0);
expect(left).toBe(0);

ionic.trigger('scroll', {target: el[0], scrollTop: 3, scrollLeft: 4});
expect(top).toBe(3);
expect(left).toBe(4);
});

testWithAnimate(true);
testWithAnimate(false);
function testWithAnimate(animate) {
Expand Down

0 comments on commit 9e942f8

Please sign in to comment.