Skip to content

Commit 1055263

Browse files
committedApr 14, 2015
fix(content): make on-scroll-complete pass (scrollLeft, scrollTop) locals
Closes #2464.
1 parent bd4723c commit 1055263

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed
 

‎js/angular/directive/content.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @param {string=} start-x Initial horizontal scroll position. Default 0.
3636
* @param {string=} start-y Initial vertical scroll position. Default 0.
3737
* @param {expression=} on-scroll Expression to evaluate when the content is scrolled.
38-
* @param {expression=} on-scroll-complete Expression to evaluate when a scroll action completes.
38+
* @param {expression=} on-scroll-complete Expression to evaluate when a scroll action completes. Has access to 'scrollLeft' and 'scrollTop' locals.
3939
* @param {boolean=} has-bouncing Whether to allow scrolling to bounce past the edges
4040
* of the content. Defaults to true on iOS, false on Android.
4141
* @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) {
138138
scrollingX: $scope.direction.indexOf('x') >= 0,
139139
scrollingY: $scope.direction.indexOf('y') >= 0,
140140
scrollEventInterval: parseInt($scope.scrollEventInterval, 10) || 10,
141-
scrollingComplete: function() {
142-
$scope.$onScrollComplete({
143-
scrollTop: this.__scrollTop,
144-
scrollLeft: this.__scrollLeft
145-
});
146-
}
141+
scrollingComplete: onScrollComplete
147142
};
148143
}
149144

150145
// init scroll controller with appropriate options
151-
$controller('$ionicScroll', {
146+
var scrollCtrl = $controller('$ionicScroll', {
152147
$scope: $scope,
153148
scrollViewOptions: scrollViewOptions
154149
});
155150

151+
function onScrollComplete() {
152+
$scope.$onScrollComplete({
153+
scrollTop: scrollCtrl.scrollView.__scrollTop,
154+
scrollLeft: scrollCtrl.scrollView.__scrollLeft
155+
});
156+
}
157+
156158
$scope.$on('$destroy', function() {
157159
if (scrollViewOptions) {
158160
scrollViewOptions.scrollingComplete = noop;

‎test/unit/angular/directive/content.unit.js

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ describe('Ionic Content directive', function() {
135135
expect(element.hasClass('overflow-scroll')).toBe(true);
136136
});
137137

138+
it('should call on-scrolling-complete attribute callback with locals', function() {
139+
scope.youCompleteMe = jasmine.createSpy('scrollComplete');
140+
var element = compile('<ion-content on-scroll-complete="youCompleteMe(scrollLeft, scrollTop)">')(scope);
141+
scope.$apply();
142+
element.controller('$ionicScroll').scrollView.__scrollingComplete();
143+
expect(scope.youCompleteMe).toHaveBeenCalledWith(0, 0);
144+
});
145+
138146
});
139147
/* Tests #555, #1155 */
140148
describe('Ionic Content Directive scoping', function() {
@@ -158,4 +166,6 @@ describe('Ionic Content Directive scoping', function() {
158166
expect(input.scope().foo).toBe('bar');
159167
expect(ctrl.$scope.foo).toBe('bar');
160168
}));
169+
170+
161171
});

0 commit comments

Comments
 (0)