Skip to content

Commit

Permalink
fix(content): make on-scroll-complete pass (scrollLeft, scrollTop) lo…
Browse files Browse the repository at this point in the history
…cals

Closes #2464.
  • Loading branch information
ajoslin committed Apr 14, 2015
1 parent bd4723c commit 1055263
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions js/angular/directive/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/angular/directive/content.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ion-content on-scroll-complete="youCompleteMe(scrollLeft, scrollTop)">')(scope);
scope.$apply();
element.controller('$ionicScroll').scrollView.__scrollingComplete();
expect(scope.youCompleteMe).toHaveBeenCalledWith(0, 0);
});

});
/* Tests #555, #1155 */
describe('Ionic Content Directive scoping', function() {
Expand All @@ -158,4 +166,6 @@ describe('Ionic Content Directive scoping', function() {
expect(input.scope().foo).toBe('bar');
expect(ctrl.$scope.foo).toBe('bar');
}));


});

0 comments on commit 1055263

Please sign in to comment.