From 10552634d973959f685abb54c18b03a546ff11cf Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Apr 2015 10:53:27 -0600 Subject: [PATCH] fix(content): make on-scroll-complete pass (scrollLeft, scrollTop) locals Closes #2464. --- js/angular/directive/content.js | 18 ++++++++++-------- test/unit/angular/directive/content.unit.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/js/angular/directive/content.js b/js/angular/directive/content.js index b5260db175c..293d7b14483 100644 --- a/js/angular/directive/content.js +++ b/js/angular/directive/content.js @@ -35,7 +35,7 @@ * @param {string=} start-x Initial horizontal scroll position. Default 0. * @param {string=} start-y Initial vertical scroll position. Default 0. * @param {expression=} on-scroll Expression to evaluate when the content is scrolled. - * @param {expression=} on-scroll-complete Expression to evaluate when a scroll action completes. + * @param {expression=} on-scroll-complete Expression to evaluate when a scroll action completes. Has access to 'scrollLeft' and 'scrollTop' locals. * @param {boolean=} has-bouncing Whether to allow scrolling to bounce past the edges * of the content. Defaults to true on iOS, false on Android. * @param {number=} scroll-event-interval Number of milliseconds between each firing of the 'on-scroll' expression. Default 10. @@ -138,21 +138,23 @@ function($timeout, $controller, $ionicBind, $ionicConfig) { scrollingX: $scope.direction.indexOf('x') >= 0, scrollingY: $scope.direction.indexOf('y') >= 0, scrollEventInterval: parseInt($scope.scrollEventInterval, 10) || 10, - scrollingComplete: function() { - $scope.$onScrollComplete({ - scrollTop: this.__scrollTop, - scrollLeft: this.__scrollLeft - }); - } + scrollingComplete: onScrollComplete }; } // init scroll controller with appropriate options - $controller('$ionicScroll', { + var scrollCtrl = $controller('$ionicScroll', { $scope: $scope, scrollViewOptions: scrollViewOptions }); + function onScrollComplete() { + $scope.$onScrollComplete({ + scrollTop: scrollCtrl.scrollView.__scrollTop, + scrollLeft: scrollCtrl.scrollView.__scrollLeft + }); + } + $scope.$on('$destroy', function() { if (scrollViewOptions) { scrollViewOptions.scrollingComplete = noop; diff --git a/test/unit/angular/directive/content.unit.js b/test/unit/angular/directive/content.unit.js index bf22887f25b..efc1969e161 100644 --- a/test/unit/angular/directive/content.unit.js +++ b/test/unit/angular/directive/content.unit.js @@ -135,6 +135,14 @@ describe('Ionic Content directive', function() { expect(element.hasClass('overflow-scroll')).toBe(true); }); + it('should call on-scrolling-complete attribute callback with locals', function() { + scope.youCompleteMe = jasmine.createSpy('scrollComplete'); + var element = compile('')(scope); + scope.$apply(); + element.controller('$ionicScroll').scrollView.__scrollingComplete(); + expect(scope.youCompleteMe).toHaveBeenCalledWith(0, 0); + }); + }); /* Tests #555, #1155 */ describe('Ionic Content Directive scoping', function() { @@ -158,4 +166,6 @@ describe('Ionic Content Directive scoping', function() { expect(input.scope().foo).toBe('bar'); expect(ctrl.$scope.foo).toBe('bar'); })); + + });