diff --git a/js/ext/angular/src/service/delegates/ionicScrollDelegate.js b/js/ext/angular/src/service/delegates/ionicScrollDelegate.js index e3d6b4232d1..445d38ab441 100644 --- a/js/ext/angular/src/service/delegates/ionicScrollDelegate.js +++ b/js/ext/angular/src/service/delegates/ionicScrollDelegate.js @@ -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); diff --git a/js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js b/js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js index a958c3b9859..063feab16b5 100644 --- a/js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js +++ b/js/ext/angular/test/service/delegates/ionicScrollDelegate.unit.js @@ -31,6 +31,26 @@ describe('Ionic ScrollDelegate Service', function() { expect(sv.resize).toHaveBeenCalled(); }); + it('scroll event', function() { + var scope = rootScope.$new(); + var el = compile('')(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) {