feat($ionicScrollDelegate): add getScrollView(), getScrollPosition()

Closes #1117
This commit is contained in:
Andy Joslin
2014-04-11 14:00:21 -06:00
parent 5ff15c0c63
commit b5ef9313cf
2 changed files with 33 additions and 0 deletions

View File

@@ -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
@@ -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
@@ -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);
};

View File

@@ -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() {