From bea69fe46c01856189fe509c5c2159760087d6d5 Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Thu, 12 Jun 2014 09:23:30 -0600 Subject: [PATCH] amend(platform-backButton): do not set icon if icon child exists --- js/angular/directive/navBackButton.js | 4 +++- .../unit/angular/directive/navBackButton.unit.js | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/js/angular/directive/navBackButton.js b/js/angular/directive/navBackButton.js index 1f3b365c79..dace89c79b 100644 --- a/js/angular/directive/navBackButton.js +++ b/js/angular/directive/navBackButton.js @@ -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); } diff --git a/test/unit/angular/directive/navBackButton.unit.js b/test/unit/angular/directive/navBackButton.unit.js index 1189358fb4..a3aaf6b811 100644 --- a/test/unit/angular/directive/navBackButton.unit.js +++ b/test/unit/angular/directive/navBackButton.unit.js @@ -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('', ''); + 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'); });