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'); var item = document.createElement('a');
item.className = 'tab-item'; item.className = 'tab-item';
// If there is an icon, add the icon element
if(itemData.icon) { if(itemData.icon) {
var icon = document.createElement('i'); var icon = document.createElement('i');
icon.className = itemData.icon; icon.className = itemData.icon;
@ -108,7 +109,8 @@ TabBar.prototype = {
if(!this._itemTapHandler) { if(!this._itemTapHandler) {
this._itemTapHandler = function(e) { this._itemTapHandler = function(e) {
_this.selectItem(this); //_this.selectItem(this);
_this.trySelectItem(this);
}; };
} }
item.onTap = this._itemTapHandler; item.onTap = this._itemTapHandler;
@ -131,7 +133,7 @@ TabBar.prototype = {
// Select the new item // Select the new item
if(this.selectedItem) { if(this.selectedItem) {
this.selectedItem.setSelected(true); 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. // Build the initial items list from the given DOM node.
_buildItems: function() { _buildItems: function() {

View File

@ -19,7 +19,7 @@ TabBarController.prototype = {
_bindEvents: function() { _bindEvents: function() {
var _this = this; var _this = this;
this.tabBar.onTabSelected = function(item, index) { this.tabBar.tryTabSelect = function(index) {
_this.setSelectedController(index); _this.setSelectedController(index);
}; };
}, },

View File

@ -42,7 +42,7 @@
</p> </p>
</div> </div>
</main> </main>
<nav id="tab-bar" class="tabs tabs-default"> <nav id="tab-bar" class="tabs tabs-success">
<a class="tab-item" href="#"> <a class="tab-item" href="#">
<i class="icon-home"></i> <i class="icon-home"></i>
Friends Friends