Skip to content

Commit b5ef931

Browse files
committed
feat($ionicScrollDelegate): add getScrollView(), getScrollPosition()
Closes #1117
1 parent 5ff15c0 commit b5ef931

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: js/ext/angular/src/controller/ionicScrollController.js

+22
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ angular.module('ionic.ui.scroll')
9494
* @param {boolean=} shouldAnimate Whether the scroll should animate.
9595
*/
9696
'scrollBy',
97+
/**
98+
* @ngdoc method
99+
* @name $ionicScrollDelegate#getScrollPosition
100+
* @returns {object} The scroll position of this view, with the following properties:
101+
* - `{number}` `left` The distance the user has scrolled from the left (starts at 0).
102+
* - `{number}` `top` The distance the user has scrolled from the top (starts at 0).
103+
*/
104+
'getScrollPosition',
97105
/**
98106
* @ngdoc method
99107
* @name $ionicScrollDelegate#anchorScroll
@@ -105,6 +113,12 @@ angular.module('ionic.ui.scroll')
105113
* @param {boolean=} shouldAnimate Whether the scroll should animate.
106114
*/
107115
'anchorScroll',
116+
/**
117+
* @ngdoc method
118+
* @name $ionicScrollDelegate.#getScrollView
119+
* @returns {object} The scrollView associated with this delegate.
120+
*/
121+
'getScrollView',
108122
/**
109123
* @ngdoc method
110124
* @name $ionicScrollDelegate#rememberScrollPosition
@@ -272,6 +286,14 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
272286

273287
this._rememberScrollId = null;
274288

289+
this.getScrollView = function() {
290+
return this.scrollView;
291+
};
292+
293+
this.getScrollPosition = function() {
294+
return this.scrollView.getValues();
295+
};
296+
275297
this.resize = function() {
276298
return $timeout(resize);
277299
};

Diff for: js/ext/angular/test/controller/ionicScrollController.unit.js

+11
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ describe('$ionicScroll Controller', function() {
219219
expect(ctrl.scrollView.resize).toHaveBeenCalled();
220220
}));
221221

222+
it('.getScrollView', function() {
223+
setup();
224+
expect(ctrl.getScrollView()).toBe(ctrl.scrollView);
225+
});
226+
it('.getScrollPosition', function() {
227+
setup();
228+
var values = {};
229+
spyOn(ctrl.scrollView, 'getValues').andReturn(values);
230+
expect(ctrl.getScrollPosition()).toBe(values);
231+
});
232+
222233
[false, true].forEach(function(shouldAnimate) {
223234
describe('with animate='+shouldAnimate, function() {
224235

0 commit comments

Comments
 (0)