From df6dcb96f633cef043b0b25c8a8837755f350ad9 Mon Sep 17 00:00:00 2001 From: perry Date: Fri, 13 Feb 2015 11:51:06 -0600 Subject: [PATCH] fix(scroll): cleanup native scroll listeners only if activated --- js/angular/controller/refresherController.js | 10 +++++----- .../angular/controller/refreshController.unit.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/js/angular/controller/refresherController.js b/js/angular/controller/refresherController.js index b0118483f0..2d3ade2685 100644 --- a/js/angular/controller/refresherController.js +++ b/js/angular/controller/refresherController.js @@ -246,14 +246,14 @@ IonicModule ionic.on('touchmove', handleTouchmove, scrollChild); ionic.on('touchend', handleTouchend, scrollChild); ionic.on('scroll', handleScroll, scrollParent); + + // cleanup when done + $scope.$on('$destroy', destroy); }; - - $scope.$on('$destroy', destroy); - function destroy() { - ionic.off('dragdown', handleTouchmove, scrollChild); - ionic.off('dragend', handleTouchend, scrollChild); + ionic.off('touchmove', handleTouchmove, scrollChild); + ionic.off('touchend', handleTouchend, scrollChild); ionic.off('scroll', handleScroll, scrollParent); scrollParent = null; scrollChild = null; diff --git a/test/unit/angular/controller/refreshController.unit.js b/test/unit/angular/controller/refreshController.unit.js index 9ca4a4d889..beca46ee92 100644 --- a/test/unit/angular/controller/refreshController.unit.js +++ b/test/unit/angular/controller/refreshController.unit.js @@ -126,4 +126,16 @@ describe('$ionicRefresh Controller', function() { ctrl.getRefresherDomMethods().hide(); expect(refresher.classList.contains('invisible')).toBe(true); }); + + it('should cleanup when done', function() { + setup(); + + expect(ctrl.__getScrollChild()).not.toBe(null); + expect(ctrl.__getScrollParent()).not.toBe(null); + + scope.$broadcast('$destroy'); + + expect(ctrl.__getScrollChild()).toBe(null); + expect(ctrl.__getScrollParent()).toBe(null); + }); });