From f847c2084774f51731239def71bd2612af5fc141 Mon Sep 17 00:00:00 2001 From: flmu Date: Mon, 31 Mar 2014 11:34:08 +0200 Subject: [PATCH] feat($ionicScrollDelegate): add scrollBy(left,top,animate) to delegate Closes #987 --- .../src/controller/ionicScrollController.js | 14 ++++++++++++++ .../test/controller/ionicScrollController.unit.js | 5 +++++ js/views/scrollView.js | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/js/ext/angular/src/controller/ionicScrollController.js b/js/ext/angular/src/controller/ionicScrollController.js index b199241354..947ccededf 100644 --- a/js/ext/angular/src/controller/ionicScrollController.js +++ b/js/ext/angular/src/controller/ionicScrollController.js @@ -86,6 +86,14 @@ angular.module('ionic.ui.scroll') * @param {boolean=} shouldAnimate Whether the scroll should animate. */ 'scrollTo', + /** + * @ngdoc method + * @name $ionicScrollDelegate#scrollBy + * @param {number} left The x-offset to scroll by. + * @param {number} top The y-offset to scroll by. + * @param {boolean=} shouldAnimate Whether the scroll should animate. + */ + 'scrollBy', /** * @ngdoc method * @name $ionicScrollDelegate#anchorScroll @@ -287,6 +295,12 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca }); }; + this.scrollBy = function(left, top, shouldAnimate) { + this.resize().then(function() { + scrollView.scrollBy(left, top, !!shouldAnimate); + }); + }; + this.anchorScroll = function(shouldAnimate) { this.resize().then(function() { var hash = $location.hash(); diff --git a/js/ext/angular/test/controller/ionicScrollController.unit.js b/js/ext/angular/test/controller/ionicScrollController.unit.js index d9c9556a6f..1d045e969a 100644 --- a/js/ext/angular/test/controller/ionicScrollController.unit.js +++ b/js/ext/angular/test/controller/ionicScrollController.unit.js @@ -257,6 +257,11 @@ describe('$ionicScroll Controller', function() { ctrl.scrollTo(1, 2, shouldAnimate); expect(ctrl.scrollView.scrollTo).toHaveBeenCalledWith(1, 2, shouldAnimate); }); + it('.scrollBy', function() { + spyOn(ctrl.scrollView, 'scrollBy'); + ctrl.scrollBy(1, 2, shouldAnimate); + expect(ctrl.scrollView.scrollBy).toHaveBeenCalledWith(1, 2, shouldAnimate); + }); it('.anchorScroll without hash should scrollTop', inject(function($location, $document) { $document[0].getElementById = jasmine.createSpy(); $location.hash = function() { return null; }; diff --git a/js/views/scrollView.js b/js/views/scrollView.js index ac423525e4..cd88c65b73 100644 --- a/js/views/scrollView.js +++ b/js/views/scrollView.js @@ -1313,7 +1313,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ * Scroll by the given offset * * @param left {Number} Scroll x-axis by given offset - * @param top {Number} Scroll x-axis by given offset + * @param top {Number} Scroll y-axis by given offset * @param animate {Boolean} Whether to animate the given change */ scrollBy: function(left, top, animate) {