Skip to content

Commit

Permalink
feat($ionicScrollDelegate): add getScrollView(), getScrollPosition()
Browse files Browse the repository at this point in the history
Closes #1117
  • Loading branch information
ajoslin committed Apr 11, 2014
1 parent 5ff15c0 commit b5ef931
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions js/ext/angular/src/controller/ionicScrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ angular.module('ionic.ui.scroll')
* @param {boolean=} shouldAnimate Whether the scroll should animate.
*/
'scrollBy',
/**
* @ngdoc method
* @name $ionicScrollDelegate#getScrollPosition
* @returns {object} The scroll position of this view, with the following properties:
* - `{number}` `left` The distance the user has scrolled from the left (starts at 0).
* - `{number}` `top` The distance the user has scrolled from the top (starts at 0).
*/
'getScrollPosition',
/**
* @ngdoc method
* @name $ionicScrollDelegate#anchorScroll
Expand All @@ -105,6 +113,12 @@ angular.module('ionic.ui.scroll')
* @param {boolean=} shouldAnimate Whether the scroll should animate.
*/
'anchorScroll',
/**
* @ngdoc method
* @name $ionicScrollDelegate.#getScrollView
* @returns {object} The scrollView associated with this delegate.
*/
'getScrollView',
/**
* @ngdoc method
* @name $ionicScrollDelegate#rememberScrollPosition
Expand Down Expand Up @@ -272,6 +286,14 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca

this._rememberScrollId = null;

this.getScrollView = function() {
return this.scrollView;
};

this.getScrollPosition = function() {
return this.scrollView.getValues();
};

this.resize = function() {
return $timeout(resize);
};
Expand Down
11 changes: 11 additions & 0 deletions js/ext/angular/test/controller/ionicScrollController.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ describe('$ionicScroll Controller', function() {
expect(ctrl.scrollView.resize).toHaveBeenCalled();
}));

it('.getScrollView', function() {
setup();
expect(ctrl.getScrollView()).toBe(ctrl.scrollView);
});
it('.getScrollPosition', function() {
setup();
var values = {};
spyOn(ctrl.scrollView, 'getValues').andReturn(values);
expect(ctrl.getScrollPosition()).toBe(values);
});

[false, true].forEach(function(shouldAnimate) {
describe('with animate='+shouldAnimate, function() {

Expand Down

0 comments on commit b5ef931

Please sign in to comment.