diff --git a/js/angular/controller/headerBarController.js b/js/angular/controller/headerBarController.js index e5c3680e6b..759364516b 100644 --- a/js/angular/controller/headerBarController.js +++ b/js/angular/controller/headerBarController.js @@ -112,15 +112,15 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) { }; - self.alignTitle = function(align) { + self.align = function(textAlign) { var titleEle = getEle(TITLE); - align = align || $attrs.alignTitle || $ionicConfig.navBar.alignTitle(); + textAlign = textAlign || $attrs.alignTitle || $ionicConfig.navBar.alignTitle(); - var widths = self.calcWidths(align, false); + var widths = self.calcWidths(textAlign, false); if (isBackShown && previousTitleText && $ionicConfig.backButton.previousTitleText()) { - var previousTitleWidths = self.calcWidths(align, true); + var previousTitleWidths = self.calcWidths(textAlign, true); var availableTitleWidth = $element[0].offsetWidth - previousTitleWidths.titleLeft - previousTitleWidths.titleRight; @@ -133,7 +133,7 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) { }; - self.calcWidths = function(align, isPreviousTitle) { + self.calcWidths = function(textAlign, isPreviousTitle) { var titleEle = getEle(TITLE); var backBtnEle = getEle(BACK_BUTTON); var x, y, z, b, c, d, childSize, bounds; @@ -216,7 +216,7 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) { // Size and align the header titleEle based on the sizes of the left and // right children, and the desired alignment mode - if (align == 'left') { + if (textAlign == 'left') { updateCss = 'title-left'; if (buttonsLeft) { updateTitleLeft = buttonsLeft + 15; @@ -225,7 +225,7 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) { updateTitleRight = buttonsRight + 15; } - } else if (align == 'right') { + } else if (textAlign == 'right') { updateCss = 'title-right'; if (buttonsLeft) { updateTitleLeft = buttonsLeft + 15; diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index 2e00cd245c..71fd2a1254 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -250,7 +250,7 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io navBarTransition.run(0); - $timeout(enteringHeaderBarCtrl.alignTitle, 16); + $timeout(enteringHeaderBarCtrl.align, 16); queuedTransitionStart = function() { if (latestTransitionId !== transitionId) return; @@ -327,6 +327,7 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io headerBar = headerBar || getOnScreenHeaderBar(); headerBar && headerBar.showBack(show); $scope.$isBackButtonShown = !!show; + return !!show; }; @@ -341,6 +342,12 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io }; + self.align = function(val, headerBar) { + headerBar = headerBar || getOnScreenHeaderBar(); + headerBar && headerBar.controller().align(val); + }; + + function createNavElement(type) { if (navElementHtml[type]) { return jqLite(navElementHtml[type]); diff --git a/js/angular/directive/headerFooterBar.js b/js/angular/directive/headerFooterBar.js index b7269bc510..2db0f6e5d7 100644 --- a/js/angular/directive/headerFooterBar.js +++ b/js/angular/directive/headerFooterBar.js @@ -139,7 +139,7 @@ function headerFooterBarDirective(isHeader) { delete $scope.$hasHeader; delete $scope.$hasSubheader; }); - ctrl.alignTitle(); + ctrl.align(); $scope.$emit('ionHeaderBar.init'); } else { diff --git a/test/unit/angular/directive/navBar.unit.js b/test/unit/angular/directive/navBar.unit.js index e2e087574e..117830f400 100644 --- a/test/unit/angular/directive/navBar.unit.js +++ b/test/unit/angular/directive/navBar.unit.js @@ -125,6 +125,46 @@ describe('ionNavBar', function() { expect(deregisterSpy).toHaveBeenCalled(); })); + it('should align title w/ $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) { + var el = setup('delegate-handle="theBestHandle"'); + var instance = $ionicNavBarDelegate.$getByHandle('theBestHandle'); + instance.align('right'); + expect(el[0].querySelector('[nav-bar="active"] .title').classList.contains('title-right')).toEqual(true); + })); + + it('should showBackButton w/ $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) { + var el = setup('delegate-handle="theBestHandle"'); + var instance = $ionicNavBarDelegate.$getByHandle('theBestHandle'); + instance.showBackButton(true); + instance.showBackButton(false); + })); + + it('should showBar w/ $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) { + var el = setup('delegate-handle="theBestHandle"'); + var instance = $ionicNavBarDelegate.$getByHandle('theBestHandle'); + instance.showBar(true); + expect(el.hasClass('hide')).toBe(false); + instance.showBar(false); + expect(el.hasClass('hide')).toBe(true); + })); + + it('should set title w/ $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) { + var el = setup('delegate-handle="theBestHandle"'); + var instance = $ionicNavBarDelegate.$getByHandle('theBestHandle'); + expect(el[0].querySelector('[nav-bar="active"] .title').innerText).toEqual(''); + instance.title('Night Ranger') + expect(el[0].querySelector('[nav-bar="active"] .title').innerText).toEqual('Night Ranger'); + })); + + it('should update w/ $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) { + var el = setup('delegate-handle="theBestHandle"'); + var instance = $ionicNavBarDelegate.$getByHandle('theBestHandle'); + instance.update({ + showBar: false + }); + expect(el.hasClass('hide')).toBe(true); + })); + }); });