From 51ed1824d5320ac788c9d27561338a61cbf844bc Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 13 Feb 2015 11:34:12 -0600 Subject: [PATCH] fix(sidemenu): prevent scroll during menu drag Closes #2808 --- js/angular/controller/scrollController.js | 2 +- js/angular/controller/sideMenuController.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/js/angular/controller/scrollController.js b/js/angular/controller/scrollController.js index b7d55a0664..b84689253f 100644 --- a/js/angular/controller/scrollController.js +++ b/js/angular/controller/scrollController.js @@ -162,7 +162,7 @@ function($scope, self.freezeAllScrolls = function(shouldFreeze) { for (var i = 0; i < $ionicScrollDelegate._instances.length; i++) { - $ionicScrollDelegate._instances[x].freezeScroll(shouldFreeze); + $ionicScrollDelegate._instances[i].freezeScroll(shouldFreeze); } }; diff --git a/js/angular/controller/sideMenuController.js b/js/angular/controller/sideMenuController.js index 2580029d56..d912b9b4a7 100644 --- a/js/angular/controller/sideMenuController.js +++ b/js/angular/controller/sideMenuController.js @@ -6,7 +6,8 @@ IonicModule '$ionicPlatform', '$ionicBody', '$ionicHistory', -function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory) { + '$ionicScrollDelegate', +function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $ionicHistory, $ionicScrollDelegate) { var self = this; var rightShowing, leftShowing, isDragging; var startX, lastX, offsetX, isAsideExposed; @@ -148,8 +149,20 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io // add the CSS class "menu-open" if the percentage does not // equal 0, otherwise remove the class from the body element $ionicBody.enableClass((percentage !== 0), 'menu-open'); + + freezeAllScrolls(false); }; + function freezeAllScrolls(shouldFreeze) { + if (shouldFreeze && !self.isScrollFreeze) { + $ionicScrollDelegate.freezeAllScrolls(shouldFreeze); + + } else if (!shouldFreeze && self.isScrollFreeze) { + $ionicScrollDelegate.freezeAllScrolls(false); + } + self.isScrollFreeze = shouldFreeze; + } + /** * Open the menu the given pixel amount. * @param {float} amount the pixel amount to open the menu. Positive value for left menu, @@ -297,6 +310,8 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io // End a drag with the given event self._endDrag = function(e) { + freezeAllScrolls(false); + if (isAsideExposed) return; if (isDragging) { @@ -334,6 +349,7 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io if (isDragging) { self.openAmount(offsetX + (lastX - startX)); + freezeAllScrolls(true); } }; @@ -415,6 +431,9 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io self.content.element = null; self.content = null; } + + // ensure scrolls are unfrozen + freezeAllScrolls(false); }); self.initialize({