From 61916c61bbd1b145933cf66b45c5ede95082b1b2 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 25 Nov 2014 09:37:58 -0600 Subject: [PATCH] fix(delegate): find delegate when multiple parent histories --- js/angular/service/history.js | 13 ++++--------- test/unit/angular/service/history.unit.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/js/angular/service/history.js b/js/angular/service/history.js index 6636865053..025904067b 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -645,23 +645,18 @@ function($rootScope, $state, $location, $window, $ionicViewSwitcher, $ionicNavVi if (!scope) return false; var climbScope = scope; - var historyId; + var currentHistoryId = this.currentHistoryId(); while (climbScope) { if (climbScope.$$disconnected) { return false; } - if (!historyId && climbScope.hasOwnProperty('$historyId')) { - historyId = climbScope.$historyId; + if (currentHistoryId && currentHistoryId == climbScope.$historyId) { + return true; } climbScope = climbScope.$parent; } - var currentHistoryId = this.currentHistoryId(); - if (currentHistoryId) { - return currentHistoryId == (historyId || 'root'); - } - - return true; + return currentHistoryId ? currentHistoryId == 'root' : true; } }; diff --git a/test/unit/angular/service/history.unit.js b/test/unit/angular/service/history.unit.js index 9fe08c4db6..bd493af3a2 100644 --- a/test/unit/angular/service/history.unit.js +++ b/test/unit/angular/service/history.unit.js @@ -1161,6 +1161,25 @@ describe('Ionic History', function() { expect(ionicHistory.isActiveScope(scope)).toEqual(true); }); + it('should be active when one of the parent scopes is the same history id as current view', function() { + ionicHistory.currentView({ + historyId: '123' + }); + + var scope = { + $parent: { + $historyId: 'abc', + $parent: { + $historyId: 'xyz', + $parent: { + $historyId: '123' + } + } + } + } + expect(ionicHistory.isActiveScope(scope)).toEqual(true); + }); + it('should be not active w/ scope different history id as current view', function() { ionicHistory.currentView({ historyId: '123'