From b5ef9313cfd227c716a2096a5ca40d38179ba50f Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Fri, 11 Apr 2014 14:00:21 -0600 Subject: [PATCH] feat($ionicScrollDelegate): add getScrollView(), getScrollPosition() Closes #1117 --- .../src/controller/ionicScrollController.js | 22 +++++++++++++++++++ .../controller/ionicScrollController.unit.js | 11 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/js/ext/angular/src/controller/ionicScrollController.js b/js/ext/angular/src/controller/ionicScrollController.js index 39d704c65e2..c047f4abfb7 100644 --- a/js/ext/angular/src/controller/ionicScrollController.js +++ b/js/ext/angular/src/controller/ionicScrollController.js @@ -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); }; diff --git a/js/ext/angular/test/controller/ionicScrollController.unit.js b/js/ext/angular/test/controller/ionicScrollController.unit.js index 1d045e969ac..3b21a9ff0cd 100644 --- a/js/ext/angular/test/controller/ionicScrollController.unit.js +++ b/js/ext/angular/test/controller/ionicScrollController.unit.js @@ -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() {