Skip to content

Commit

Permalink
fix(ionHeaderBar): have no side effects with content in other views
Browse files Browse the repository at this point in the history
Closes #1095
  • Loading branch information
ajoslin committed Apr 29, 2014
1 parent b87bcb3 commit 7fd31b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
18 changes: 9 additions & 9 deletions js/angular/directive/headerFooterBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function tapScrollToTopDirective() {
current.tagName.match(/input|textarea|select/i) ||
current.isContentEditable) {
return;
}
}
current = current.parentNode;
}
var touch = e.gesture && e.gesture.touches[0] || e.detail.touches[0];
Expand Down Expand Up @@ -121,26 +121,26 @@ function headerFooterBarDirective(isHeader) {
});

var el = $element[0];
//just incase header is on rootscope
var parentScope = $scope.$parent || $scope;

if (isHeader) {
$scope.$watch(function() { return el.className; }, function(value) {
var isSubheader = value.indexOf('bar-subheader') !== -1;
parentScope.$hasHeader = !isSubheader;
parentScope.$hasSubheader = isSubheader;
$scope.$hasHeader = !isSubheader;
$scope.$hasSubheader = isSubheader;
});
$scope.$on('$destroy', function() {
parentScope.$hasHeader = parentScope.$hasSubheader = null;
delete $scope.$hasHeader;
delete $scope.$hasSubheader;
});
} else {
$scope.$watch(function() { return el.className; }, function(value) {
var isSubfooter = value.indexOf('bar-subfooter') !== -1;
parentScope.$hasFooter = !isSubfooter;
parentScope.$hasSubfooter = isSubfooter;
$scope.$hasFooter = !isSubfooter;
$scope.$hasSubfooter = isSubfooter;
});
$scope.$on('$destroy', function() {
parentScope.$hasFooter = parentScope.$hasSubfooter = null;
delete $scope.$hasFooter;
delete $scope.$hasSubfooter;
});
$scope.$watch('$hasTabs', function(val) {
$element.toggleClass('has-tabs', !!val);
Expand Down
3 changes: 2 additions & 1 deletion js/angular/directive/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ IonicModule
$scope.$hasTabsTop = isTabsTop && !isHidden;
});
$scope.$on('$destroy', function() {
$scope.$hasTabs = $scope.$hasTabsTop = null;
delete $scope.$hasTabs;
delete $scope.$hasTabsTop;
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/html/viewState.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ <h3>Information</h3>
</button>
</ion-nav-buttons>
<ion-view title="Auto List">
<ion-header-bar class="bar bar-subheader bar-energized">
<h1 class="title">some subheader</h1>
</ion-header-bar>
<ion-content padding="true">
<ion-list>
<ion-item ng-repeat="auto in autos"
Expand Down
6 changes: 3 additions & 3 deletions test/unit/angular/directive/headerFooterBar.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('bar directives', function() {
if (data.tag === 'ion-header-bar') {
it('$hasHeader $hasSubheader', function() {
var el = setup();
var scope = el.scope().$parent;
var scope = el.scope();
expect(scope.$hasHeader).toEqual(true);
expect(scope.$hasSubheader).toEqual(false);
el.addClass('bar-subheader');
Expand All @@ -113,7 +113,7 @@ describe('bar directives', function() {
} else {
it('$hasFooter $hasSubheader', function() {
var el = setup();
var scope = el.scope().$parent;
var scope = el.scope();
expect(scope.$hasFooter).toEqual(true);
expect(scope.$hasSubfooter).toEqual(false);
el.addClass('bar-subfooter');
Expand All @@ -127,7 +127,7 @@ describe('bar directives', function() {
});
it('.has-tabs', function() {
var el = setup();
var scope = el.scope().$parent;
var scope = el.scope();
expect(el.hasClass('has-tabs')).toBe(false);
scope.$apply('$hasTabs = true');
expect(el.hasClass('has-tabs')).toBe(true);
Expand Down

0 comments on commit 7fd31b6

Please sign in to comment.