amend(platform-backButton): do not set icon if icon child exists

This commit is contained in:
Andrew Joslin
2014-06-12 09:23:30 -06:00
parent e4ab045e30
commit bea69fe46c
2 changed files with 16 additions and 4 deletions

View File

@@ -80,10 +80,12 @@ function($animate, $rootScope, $sanitize, $ionicNavBarConfig, $ionicNgClick) {
compile: function(tElement, tAttrs) {
tElement.addClass('button back-button ng-hide');
var hasIconChild = !!(tElement.html() || '').match(/class=.*?ion-/);
return function($scope, $element, $attr, navBarCtrl) {
// Add a default back button icon based on the nav config, unless one is set
if($element[0].className.indexOf('ion-') < 0) {
if (!hasIconChild && $element[0].className.indexOf('ion-') === -1) {
$element.addClass($ionicNavBarConfig.backButtonIcon);
}

View File

@@ -78,19 +78,29 @@ describe('ionNavBackButton directive', function() {
});
describe('ionNavBackButton directive: Platforms', function() {
describe('ionNavBackButton directive: iOS Platform', function() {
describe('platforms', function() {
describe('iOS', function() {
beforeEach(function($provide) {
TestUtil.setPlatform('ios');
});
it('should not set default back button icon if icon classname exists', function() {
var el = setup('class="ion-navicon"');
expect(el.hasClass('ion-ios7-arrow-back')).toBe(false);
});
it('should not set default back button icon if icon child exists', function() {
var el = setup('', '<i class="ion-superstar"></i>');
expect(el.hasClass('ion-ios7-arrow-back')).toBe(false);
});
it('Should set default back button icon from ionicNavBarConfig ', inject(function($ionicNavBarConfig) {
var el = setup();
expect(el.hasClass('ion-ios7-arrow-back')).toBe(true);
}));
});
describe('ionNavBackButton directive: Android Platform', function() {
describe('android', function() {
beforeEach(function($provide) {
TestUtil.setPlatform('android');
});