From 0facb120c74f010a0a60e9e70c388b5b8264b890 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Thu, 6 Feb 2014 22:12:42 -0500 Subject: [PATCH] feat(tab): allow html in tab `title` attribute Closes #528 --- js/ext/angular/src/directive/ionicTabBar.js | 15 +++-- .../test/directive/ionicTabBar.unit.js | 66 +++++++------------ js/ext/angular/test/tabs.html | 2 +- 3 files changed, 34 insertions(+), 49 deletions(-) diff --git a/js/ext/angular/src/directive/ionicTabBar.js b/js/ext/angular/src/directive/ionicTabBar.js index f84d6dc704a..25bf14cb043 100644 --- a/js/ext/angular/src/directive/ionicTabBar.js +++ b/js/ext/angular/src/directive/ionicTabBar.js @@ -1,4 +1,4 @@ -angular.module('ionic.ui.tabs', ['ionic.service.view']) +angular.module('ionic.ui.tabs', ['ionic.service.view', 'ionic.ui.bindHtml']) /** * @description @@ -93,7 +93,7 @@ angular.module('ionic.ui.tabs', ['ionic.service.view']) $scope.tabsController = this; }], - + template: '
', compile: function(element, attr, transclude, tabsCtrl) { @@ -245,8 +245,8 @@ angular.module('ionic.ui.tabs', ['ionic.service.view']) transclude: true, replace: true, scope: true, - template: '
' + - '' + + template: '
' + + '' + '
', link: function($scope, $element, $attr, tabsCtrl) { $element.addClass($scope.tabsType); @@ -274,17 +274,18 @@ angular.module('ionic.ui.tabs', ['ionic.service.view']) if(attrs.icon) { scope.iconOn = scope.iconOff = attrs.icon; } - + scope.selectTab = function() { tabsCtrl.select(scope.index, true); }; }, - template: + template: '' + '{{badge}}' + '' + '' + - ' {{iconTitle}}' + + '' + + '' + '' }; }]); diff --git a/js/ext/angular/test/directive/ionicTabBar.unit.js b/js/ext/angular/test/directive/ionicTabBar.unit.js index 716f72d0527..1bdb4d35bae 100644 --- a/js/ext/angular/test/directive/ionicTabBar.unit.js +++ b/js/ext/angular/test/directive/ionicTabBar.unit.js @@ -2,7 +2,7 @@ describe('Tab Bar Controller', function() { var compile, element, scope, ctrl; beforeEach(module('ionic.ui.tabs')); - + beforeEach(inject(function($compile, $rootScope, $controller) { compile = $compile; scope = $rootScope; @@ -63,20 +63,20 @@ describe('Tab Bar Controller', function() { describe('Tabs directive', function() { var compile, element, scope; - + beforeEach(module('ionic.ui.tabs')); beforeEach(inject(function($compile, $rootScope) { compile = $compile; scope = $rootScope; })); - + it('Has tab class', function() { element = compile('')(scope); scope.$digest(); expect(element.find('.tabs').hasClass('tabs')).toBe(true); }); - + it('Has tab children', function() { element = compile('')(scope); scope = element.scope(); @@ -90,18 +90,18 @@ describe('Tabs directive', function() { }); it('Has compiled children', function() { - element = compile('' + - '' + - '' + + element = compile('' + + '' + + '' + '')(scope); scope.$digest(); expect(element.find('a').length).toBe(2); }); it('Sets style on child tabs', function() { - element = compile('' + - '' + - '' + + element = compile('' + + '' + + '' + '')(scope); scope.$digest(); var tabs = element[0].querySelector('.tabs'); @@ -110,9 +110,9 @@ describe('Tabs directive', function() { }); it('Has nav-view', function() { - element = compile('' + - '' + - 'content2' + + element = compile('' + + '' + + 'content2' + '')(scope); scope = element.scope(); scope.$digest(); @@ -129,7 +129,7 @@ describe('Tabs directive', function() { describe('Tab Item directive', function() { var compile, element, scope, ctrl; - + beforeEach(module('ionic.ui.tabs')); beforeEach(inject(function($compile, $rootScope, $document, $controller) { @@ -138,23 +138,16 @@ describe('Tab Item directive', function() { scope.badgeValue = 3; element = compile('' + - '' + + '' + '')(scope); scope.$digest(); $document[0].body.appendChild(element[0]); })); - - it('Default text works', function() { - var title = ''; - var a = element.find('a')[0]; - for(i = 0, j = a.childNodes.length; i < j; i++) { - child = a.childNodes[i]; - if (child.nodeName === "#text") { - title += child.nodeValue.trim(); - } - } - expect(title).toEqual('Item'); + it('Title works', function() { + //The badge's text gets in the way of just doing .text() on the element itself, so exclude it + var notBadge = angular.element(element[0].querySelectorAll('a >:not(.badge)')); + expect(notBadge.text().trim()).toEqual('Item'); }); it('Default icon works', function() { @@ -189,7 +182,7 @@ describe('Tab Item directive', function() { describe('Tab Controller Item directive', function() { var compile, element, scope, ctrl; - + beforeEach(module('ionic.ui.tabs')); beforeEach(inject(function($compile, $rootScope, $document, $controller) { @@ -198,24 +191,15 @@ describe('Tab Controller Item directive', function() { scope.badgeValue = 3; scope.isActive = false; - element = compile('' + - '' + + element = compile('' + + '' + '')(scope); scope.$digest(); $document[0].body.appendChild(element[0]); })); - - it('Icon title works', function() { - var title = ''; - var a = element.find('a')[0]; - for(var i = 0, j = a.childNodes.length; i < j; i++) { - child = a.childNodes[i]; - - if (child.nodeName === "#text") { - title += child.nodeValue.trim(); - } - } - expect(title).toEqual('Icon title'); + + it('Icon title works as html', function() { + expect(element.find('a').find('span').html()).toEqual('Icon title'); }); it('Icon classes works', function() { diff --git a/js/ext/angular/test/tabs.html b/js/ext/angular/test/tabs.html index e2f2a695e89..37c1b944467 100644 --- a/js/ext/angular/test/tabs.html +++ b/js/ext/angular/test/tabs.html @@ -58,7 +58,7 @@ tabs-style="tabs-top tabs-positive" controller-changed="onControllerChanged(oldController, oldIndex, newController, newIndex)"> - +

Tasks