From 6a1c53301cf51d1ffbd3bd5ca89f7268806dad96 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 3 Dec 2014 23:28:00 -0600 Subject: [PATCH] fix(sideMenu): enable menu w/ different historyId back view --- js/angular/controller/sideMenuController.js | 7 ++- js/angular/service/history.js | 14 ++++-- test/unit/angular/directive/sideMenu.unit.js | 49 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/js/angular/controller/sideMenuController.js b/js/angular/controller/sideMenuController.js index cf0fd80d96..cefc5eb74e 100644 --- a/js/angular/controller/sideMenuController.js +++ b/js/angular/controller/sideMenuController.js @@ -368,7 +368,12 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform, $ionicBody, $io startX <= self.edgeThreshold || startX >= self.content.element.offsetWidth - self.edgeThreshold; - var menuEnabled = self.enableMenuWithBackViews() ? true : !$ionicHistory.backView(); + var backView = $ionicHistory.backView(); + var menuEnabled = enableMenuWithBackViews ? true : !backView; + if (!menuEnabled) { + var currentView = $ionicHistory.currentView() || {}; + return backView.historyId !== currentView.historyId; + } return ($scope.dragContent || self.isOpen()) && dragIsWithinBounds && diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 504db8c8d9..aa93b8897c 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -482,9 +482,12 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ * @description Returns the view that was before the current view in the history stack. * If the user navigated from View A to View B, then View A would be the back view, and * View B would be the current view. - * @returns {string} Returns the back view. + * @returns {object} Returns the back view. */ - backView: function() { + backView: function(view) { + if (arguments.length) { + viewHistory.backView = view; + } return viewHistory.backView; }, @@ -507,9 +510,12 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ * A forward view would exist if the user navigated from View A to View B, then * navigated back to View A. At this point then View B would be the forward view, and View * A would be the current view. - * @returns {string} Returns the back view. + * @returns {object} Returns the forward view. */ - forwardView: function() { + forwardView: function(view) { + if (arguments.length) { + viewHistory.forwardView = view; + } return viewHistory.forwardView; }, diff --git a/test/unit/angular/directive/sideMenu.unit.js b/test/unit/angular/directive/sideMenu.unit.js index 707eed844c..0810662d25 100644 --- a/test/unit/angular/directive/sideMenu.unit.js +++ b/test/unit/angular/directive/sideMenu.unit.js @@ -170,6 +170,55 @@ describe('Ionic Angular Side Menu', function() { expect(ctrl.isDraggableTarget(e)).toBe(true); })); + + it('should isDraggableTarget w/ enableMenuWithBackViews', inject(function($compile, $rootScope, $ionicHistory) { + var el = $compile('')($rootScope.$new()); + $rootScope.$apply(); + + var ctrl = el.controller('ionSideMenus'); + + var e = { + gesture: { + srcEvent: { + defaultPrevented: false + } + }, + target: { + tagName: 'DIV', + dataset: { + preventScroll: false + } + } + }; + + ctrl.enableMenuWithBackViews(true); + expect(ctrl.isDraggableTarget(e)).toBe(true); + + ctrl.enableMenuWithBackViews(false); + expect(ctrl.isDraggableTarget(e)).toBe(true); + + ctrl.enableMenuWithBackViews(false); + $ionicHistory.currentView({historyId: 'root'}); + $ionicHistory.backView({historyId: 'root'}); + expect(ctrl.isDraggableTarget(e)).toBe(false); + + ctrl.enableMenuWithBackViews(false); + $ionicHistory.currentView({historyId: 'root'}); + $ionicHistory.backView(null); + expect(ctrl.isDraggableTarget(e)).toBe(true); + + ctrl.enableMenuWithBackViews(true); + $ionicHistory.currentView({historyId: 'root'}); + $ionicHistory.backView({historyId: 'root'}); + expect(ctrl.isDraggableTarget(e)).toBe(true); + + ctrl.enableMenuWithBackViews(false); + $ionicHistory.currentView({historyId: '003'}); + $ionicHistory.backView({historyId: 'root'}); + expect(ctrl.isDraggableTarget(e)).toBe(true); + + })); + }); describe('Ionic Side Menu Content Directive', function () {