From 830f35dd1cb209c4324bb8e2b5c5f69bdef8e356 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Fri, 13 Sep 2013 10:09:56 -0500 Subject: [PATCH] More tests and tab item building --- hacking/TabBar.js | 35 +++++++++++++++++++++++++++++++- hacking/TabBarController.unit.js | 4 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/hacking/TabBar.js b/hacking/TabBar.js index d00d6953be..14d3e2c2d9 100644 --- a/hacking/TabBar.js +++ b/hacking/TabBar.js @@ -1,7 +1,40 @@ TabBarItem = function(el) { this.el = el; + + this._buildItem(); }; TabBarItem.prototype = { + _buildItem: function() { + var child, children = Array.prototype.slice.call(this.el.children); + + for(var i = 0, j = children.length; i < j; i++) { + child = children[i]; + + // Test if this is a "i" tag with icon in the class name + // TODO: This heuristic might not be sufficient + if(child.tagName == 'i' && /icon/.test(child.className)) { + this.icon = child; + break; + } + + // Set the title to the text content of the tab. + this.title = child.innerText.trim(); + } + }, + setIcon: function(iconClass) { + var child, children = this.el.children; + + var hasIcon = false; + for(var i = 0, j = children.length; i < j; i++) { + child = children[i]; + + } + }, + + getIcon: function() { + + }, + setSelected: function(isSelected) { this.isSelected = isSelected; if(isSelected) { @@ -40,7 +73,7 @@ TabBar.prototype = { _buildItems: function() { this.items = []; - var items = this.el.children; + var items = Array.prototype.slice.call(this.el.children); for(var i = 0, j = items.length; i < j; i += 1) { this.items[i] = new TabBarItem(items[i]); diff --git a/hacking/TabBarController.unit.js b/hacking/TabBarController.unit.js index bfb503fdca..8f6b240390 100644 --- a/hacking/TabBarController.unit.js +++ b/hacking/TabBarController.unit.js @@ -4,7 +4,7 @@ describe('TabBarController', function() { beforeEach(function() { var tabEl = $('
'); ctrl = new TabBarController({ - tabBar: new TabBar({ el: tabEl }) + tabBar: new TabBar({ el: tabEl.get(0) }) }); }) @@ -56,7 +56,7 @@ describe('TabBarController', function() { it('Should allow cancelling Controller switch', function() { var tabEl = $('
'); ctrl = new TabBarController({ - tabBar: new TabBar({ el: tabEl }), + tabBar: new TabBar({ el: tabEl.get(0) }), controllerWillChange: function(Controller) { return false; } });