From 6c32a638ad5a6b63fb9720e060a4ad4e6ae964a5 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Fri, 13 Sep 2013 18:04:05 -0500 Subject: [PATCH] Fixed TabController infinite Loop --- hacking/TabBar.js | 15 +++++++++++++-- hacking/TabBarController.js | 2 +- hacking/tabs.html | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hacking/TabBar.js b/hacking/TabBar.js index a043224279..77aefca78f 100644 --- a/hacking/TabBar.js +++ b/hacking/TabBar.js @@ -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() { diff --git a/hacking/TabBarController.js b/hacking/TabBarController.js index fc99fb6297..8a0a2f0223 100644 --- a/hacking/TabBarController.js +++ b/hacking/TabBarController.js @@ -19,7 +19,7 @@ TabBarController.prototype = { _bindEvents: function() { var _this = this; - this.tabBar.onTabSelected = function(item, index) { + this.tabBar.tryTabSelect = function(index) { _this.setSelectedController(index); }; }, diff --git a/hacking/tabs.html b/hacking/tabs.html index 171e8e525f..4b96e16203 100644 --- a/hacking/tabs.html +++ b/hacking/tabs.html @@ -42,7 +42,7 @@

-