fix($ionicNavBarDelegate): update method names

This commit is contained in:
Adam Bradley
2014-11-13 21:52:22 -06:00
parent 08353f6703
commit 04cf629fb4
4 changed files with 56 additions and 9 deletions

View File

@@ -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;

View File

@@ -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]);

View File

@@ -139,7 +139,7 @@ function headerFooterBarDirective(isHeader) {
delete $scope.$hasHeader;
delete $scope.$hasSubheader;
});
ctrl.alignTitle();
ctrl.align();
$scope.$emit('ionHeaderBar.init');
} else {

View File

@@ -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);
}));
});
});