refactored onTab to call a single function for visually turning tabs on or off depending on whether it is selected (#544)

This commit is contained in:
Tina Quach
2016-08-12 16:17:18 -05:00
committed by picklesrus
parent dd0e88b28b
commit 3748b6f8bd

View File

@@ -249,8 +249,6 @@ AppController.prototype.makeTabClickHandler_ = function(tabName) {
/**
* Called on each tab click. Hides and shows specific content based on which tab
* (Block Factory, Workspace Factory, or Exporter) is selected.
*
* TODO(quachtina96): Refactor the code to avoid repetition of addRemove.
*/
AppController.prototype.onTab = function() {
// Get tab div elements.
@@ -258,12 +256,10 @@ AppController.prototype.onTab = function() {
var exporterTab = this.tabMap['EXPORTER'];
var workspaceFactoryTab = this.tabMap['WORKSPACE_FACTORY'];
if (this.selectedTab == 'EXPORTER') {
// Turn exporter tab on and other tabs off.
goog.dom.classlist.addRemove(exporterTab, 'taboff', 'tabon');
goog.dom.classlist.addRemove(blockFactoryTab, 'tabon', 'taboff');
goog.dom.classlist.addRemove(workspaceFactoryTab, 'tabon', 'taboff');
// Turn selected tab on and other tabs off.
this.styleTabs_();
if (this.selectedTab == 'EXPORTER') {
// Update toolbox to reflect current block library.
this.exporter.updateToolbox();
@@ -272,20 +268,11 @@ AppController.prototype.onTab = function() {
BlockFactory.hide('workspaceFactoryContent');
} else if (this.selectedTab == 'BLOCK_FACTORY') {
// Turn factory tab on and other tabs off.
goog.dom.classlist.addRemove(blockFactoryTab, 'taboff', 'tabon');
goog.dom.classlist.addRemove(exporterTab, 'tabon', 'taboff');
goog.dom.classlist.addRemove(workspaceFactoryTab, 'tabon', 'taboff');
// Hide container of exporter.
BlockFactory.hide('blockLibraryExporter');
BlockFactory.hide('workspaceFactoryContent');
} else if (this.selectedTab == 'WORKSPACE_FACTORY') {
console.log('workspaceFactoryTab');
goog.dom.classlist.addRemove(workspaceFactoryTab, 'taboff', 'tabon');
goog.dom.classlist.addRemove(blockFactoryTab, 'tabon', 'taboff');
goog.dom.classlist.addRemove(exporterTab, 'tabon', 'taboff');
// Hide container of exporter.
BlockFactory.hide('blockLibraryExporter');
// Show workspace factory container.
@@ -296,6 +283,20 @@ AppController.prototype.onTab = function() {
window.dispatchEvent(new Event('resize'));
};
/**
* Called on each tab click. Styles the tabs to reflect which tab is selected.
* @private
*/
AppController.prototype.styleTabs_ = function() {
for (var tabName in this.tabMap) {
if (this.selectedTab == tabName) {
goog.dom.classlist.addRemove(this.tabMap[tabName], 'taboff', 'tabon');
} else {
goog.dom.classlist.addRemove(this.tabMap[tabName], 'tabon', 'taboff');
}
}
};
/**
* Assign button click handlers for the exporter.
*/