Messing with hack example of TabBarController and Test

This commit is contained in:
Max Lynch
2013-09-08 01:35:45 -05:00
parent 4f9cd01810
commit 56f7ee5c9c
13 changed files with 3844 additions and 0 deletions

View File

@ -0,0 +1,62 @@
TabBar = function(element) {
this.element = element;
}
TabBar.prototype = {};
TabBarController = function(options) {
this.tabBar = options.tabBar;
this.tabs = [];
// Bind or set our tabWillChange callback
this.tabWillChange = options.tabWillChange || function(tab) {};
this.tabChanged = options.tabChanged || function(tab) {};
};
TabBarController.prototype = {
selectTab: function(index) {
var shouldChange = true;
// Check if we should switch to this tab. This lets the app
// cancel tab switches if the context isn't right, for example.
if(this.tabWillChange) {
if(this.tabWillChange(this.tabs[index], index) === false) {
shouldChange = false;
}
}
if(shouldChange) {
this.selectedTab = this.tabs[index];
this.tabChanged && this.tabChanged(this.selectedTab, index);
}
},
// Return the tab at the given index
getTab: function(index) {
return this.tabs[index];
},
// Return the current tab list
getTabs: function() {
return this.tabs;
},
// Get the currently selected tab
getSelectedTab: function() {
return this.selectedTab;
},
// Add a tab
addTab: function(tab) {
this.tabs.push(tab);
if(!this.selectedTab) {
this.selectedTab = tab;
}
},
// Set the tabs and select the first
setTabs: function(tabs) {
this.tabs = tabs;
this.selectTab(0);
}
}