feat(sideMenu): make android back button close side menu

Closes #1264
This commit is contained in:
Andy Joslin
2014-05-06 10:44:26 -06:00
parent 425ba247e5
commit 101035593f
3 changed files with 58 additions and 1 deletions

View File

@@ -3,9 +3,13 @@ IonicModule
'$scope',
'$attrs',
'$ionicSideMenuDelegate',
function($scope, $attrs, $ionicSideMenuDelegate) {
'$ionicPlatform',
function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform) {
var self = this;
angular.extend(this, ionic.controllers.SideMenuController.prototype);
this.$scope = $scope;
ionic.controllers.SideMenuController.call(this, {
left: { width: 275 },
right: { width: 275 }
@@ -28,6 +32,21 @@ function($scope, $attrs, $ionicSideMenuDelegate) {
$scope.sideMenuContentTranslateX = 0;
var deregisterBackButtonAction = angular.noop;
var closeSideMenu = angular.bind(this, this.close);
$scope.$watch(function() {
return self.getOpenAmount() !== 0;
}, function(isOpen) {
deregisterBackButtonAction();
if (isOpen) {
deregisterBackButtonAction = $ionicPlatform.registerBackButtonAction(
closeSideMenu,
PLATFORM_BACK_BUTTON_PRIORITY_SIDE_MENU
);
}
});
var deregisterInstance = $ionicSideMenuDelegate._registerInstance(
this, $attrs.delegateHandle
);