Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created August 4, 2014 21:10
Show Gist options
  • Save justinhillsjohnson/f6447e41d5fa3ed8aacb to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/f6447e41d5fa3ed8aacb to your computer and use it in GitHub Desktop.
/**
* @module views/AppView
*/
define([
'jquery',
'underscore',
'backbone',
'app',
'views/BannerView',
'views/HomeView',
'views/StatsView',
'text!templates/Home.html',
'text!templates/Stats.html'
],
function(
$,
_,
Backbone,
App,
BannerView,
HomeView,
StatsView,
HomeTemplate,
StatsTemplate
) {
'use strict';
var AppView = Backbone.View.extend({
'events': {
'click .profile-nav li': 'switchContent'
},
'templates': {
'homeTemplate': _.template(HomeTemplate),
'statsTemplate': _.template(StatsTemplate)
},
'initialize': function() {
var view = this;
view.render();
view.switchContent(null, view.$el.attr('data-default-tab'));
log('App View : Initialized');
},
'render': function() {
var view = this;
view.$content = view.$('.content');
view.bannerView = new BannerView({
'el': view.$('.hero-carousel')
});
},
'switchContent': function(e, tabName) {
var view = this,
$tab, tabClass;
if (e) {
$tab = $(e.currentTarget);
tabClass = $tab.attr('class');
} else {
$tab = view.$('.' + tabName + '-tab');
tabClass = $tab.attr('class');
}
if (view.currentView !== undefined) {
view.currentView.remove();
}
if (tabClass.match(/home-tab/)) {
view.$content.append(view.templates.homeTemplate());
view.HomeView = new HomeView({
'el': view.$('.home')
});
view.currentView = view.HomeView;
} else if (tabClass.match(/stats-tab/)) {
view.$content.append(view.templates.statsTemplate());
view.StatsView = new StatsView({
'el': view.$('.stats')
});
view.currentView = view.StatsView;
} else {
// view.currentView = view.AwardsView;
}
view.$('.profile-nav li').removeClass('active');
$tab.addClass('active');
}
});
return AppView;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment