fix(isActiveScope): find active scope

Find a slide box within a modal within the active tab within a side
menu, each history with cached views. Find the active scroll view with
multiple tabs. Find a slide box when the modal is attached to the tabs
controller.
This commit is contained in:
Adam Bradley
2014-12-08 01:08:19 -06:00
parent 37dd84c6de
commit 7b39bc442e
4 changed files with 70 additions and 3 deletions

View File

@@ -88,6 +88,12 @@ IonicModule
$ionicBody.enableClass(isAsideExposed, 'aside-open');
});
$scope.$on('$ionicView.beforeEnter', function(ev, d){
if (d.historyId) {
$scope.$activeHistoryId = d.historyId;
}
});
$scope.$on('$destroy', function() {
$ionicBody.removeClass('menu-open', 'aside-open');
});

View File

@@ -663,13 +663,37 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
var climbScope = scope;
var currentHistoryId = this.currentHistoryId();
var foundHistoryId;
while (climbScope) {
if (climbScope.$$disconnected) {
return false;
}
if (currentHistoryId && (currentHistoryId == climbScope.$historyId || currentHistoryId == climbScope.$activeHistoryId)) {
return true;
if (!foundHistoryId && climbScope.hasOwnProperty('$historyId')) {
foundHistoryId = true;
}
if (currentHistoryId) {
if (climbScope.hasOwnProperty('$historyId') && currentHistoryId == climbScope.$historyId) {
return true;
}
if (climbScope.hasOwnProperty('$activeHistoryId')) {
if (currentHistoryId == climbScope.$activeHistoryId) {
if (climbScope.hasOwnProperty('$historyId')) {
return true;
}
if (!foundHistoryId) {
return true;
}
}
}
}
if (foundHistoryId && climbScope.hasOwnProperty('$activeHistoryId')) {
foundHistoryId = false;
}
climbScope = climbScope.$parent;
}

View File

@@ -69,6 +69,7 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
view = view || {};
return {
viewId: view.viewId,
historyId: view.historyId,
stateId: view.stateId,
stateName: view.stateName,
stateParams: view.stateParams

View File

@@ -1195,7 +1195,43 @@ describe('Ionic History', function() {
}
}
}
}
};
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
});
it('should be active when activeHistoryId found before historyId, for tabs controller', function() {
ionicHistory.currentView({
historyId: '123'
});
var scope = {
$parent: {
$parent: {
$activeHistoryId: '123',
$parent: {
$historyId: 'xyz'
}
}
}
};
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
});
it('should be active when historyId found before activeHistoryId', function() {
ionicHistory.currentView({
historyId: '123'
});
var scope = {
$parent: {
$parent: {
$activeHistoryId: 'xyz',
$parent: {
$historyId: '123'
}
}
}
};
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
});