Fixed TabController infinite Loop

This commit is contained in:
Max Lynch
2013-09-13 18:04:05 -05:00
parent 5e00917297
commit 6c32a638ad
3 changed files with 15 additions and 4 deletions

View File

@ -11,6 +11,7 @@ TabBarItem.prototype = {
var item = document.createElement('a');
item.className = 'tab-item';
// If there is an icon, add the icon element
if(itemData.icon) {
var icon = document.createElement('i');
icon.className = itemData.icon;
@ -108,7 +109,8 @@ TabBar.prototype = {
if(!this._itemTapHandler) {
this._itemTapHandler = function(e) {
_this.selectItem(this);
//_this.selectItem(this);
_this.trySelectItem(this);
};
}
item.onTap = this._itemTapHandler;
@ -131,7 +133,7 @@ TabBar.prototype = {
// Select the new item
if(this.selectedItem) {
this.selectedItem.setSelected(true);
this.onTabSelected && this.onTabSelected(this.selectedItem, index);
//this.onTabSelected && this.onTabSelected(this.selectedItem, index);
}
},
@ -146,6 +148,15 @@ TabBar.prototype = {
}
},
trySelectItem: function(item) {
for(var i = 0, j = this.items.length; i < j; i += 1) {
if(this.items[i] == item) {
this.tryTabSelect && this.tryTabSelect(i);
return;
}
}
},
// Build the initial items list from the given DOM node.
_buildItems: function() {