More tests and tab item building

This commit is contained in:
Max Lynch
2013-09-13 10:09:56 -05:00
parent cad4d9b0d5
commit 830f35dd1c
2 changed files with 36 additions and 3 deletions

View File

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

View File

@ -4,7 +4,7 @@ describe('TabBarController', function() {
beforeEach(function() {
var tabEl = $('<div class="tabs"></div>');
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 = $('<div class="tabs"></div>');
ctrl = new TabBarController({
tabBar: new TabBar({ el: tabEl }),
tabBar: new TabBar({ el: tabEl.get(0) }),
controllerWillChange: function(Controller) { return false; }
});