Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created January 2, 2013 18:27
Show Gist options
  • Save justinhillsjohnson/4436675 to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/4436675 to your computer and use it in GitHub Desktop.
/**
* @module Backbone
* @submodule Backbone.View
* @class MasterView
* @constructor
*/
define(function(require) {
var _ = require('underscore'),
Backbone = require('backbone'),
Views = require('global-views'),
Collections = require('global-collections');
return Backbone.View.extend({
'el': '#section-content',
'events': {
'click .modal': 'updateRoute'
},
'initialize': function(options) {
_.bindAll(this);
App.bind('ready:client', this.applyClass);
App.bind('ready:page', this.applyClass);
App.bind('route:modal', this.renderModal);
this.render();
log('Backbone : MasterView : Initialized');
},
'render': function() {
this.buildClients();
this.buildStreams();
this.buildPages();
App.views.heroView = new Views.HeroView();
// instantiate jobsView
App.views.JobsView = new Views.JobsView({
'el': '#aside-jobs'
});
this.buildModals();
},
'buildClients': function() {
var clients = [];
$('#nav-clients li').each(function() {
var $this = $(this);
var client = {
'id': $this.attr('class'),
'class': $this.attr('class'),
'title': $this.find('a').attr('title')
};
clients.push(client);
});
// instantiate clientCollection with clients[]
App.collections.clientCollection = new Collections.ClientCollection(clients);
},
'buildPages': function() {
var pages = [{
'id': 'cpb'
},
{
'id': 'work'
},
{
'id': 'about'
},
{
'id': 'contact'
},
{
'id': 'capabilities'
},
{
'id': 'jobs'
}];
// instantiate pageCollection with pages[]
App.collections.pageCollection = new Collections.PageCollection(pages);
},
'buildStreams': function() {
// TODO: add data-date to pageloaded stream groups
var tweets = [];
$('#twitter-stream .stream-item').each(function() {
var $this = $(this);
var tweet = {
'id': $this.attr('id')
};
tweets.push(tweet);
});
App.collections.tweetStreamCollection = new Collections.StreamCollection(tweets, {
'url': '/services/twitter',
'interval': 20000,
'hasMore': $('#twitter-stream').data('has-more')
});
App.views.tweetStreamView = new Views.StreamView({
'el': '#twitter-stream',
'collection': App.collections.tweetStreamCollection,
'template': _.template($('#twitter-stream-template').html())
});
var articles = [];
$('#article-stream .stream-item').each(function() {
var $this = $(this);
var article = {
'id': $this.attr('id')
};
articles.push(article);
});
App.collections.articleStreamCollection = new Collections.StreamCollection(articles, {
'url': '/services/articles',
'hasMore': $('#article-stream').data('has-more')
});
App.views.articleStreamView = new Views.StreamView({
'el': '#article-stream',
'collection': App.collections.articleStreamCollection,
'template': _.template($('#article-stream-template').html())
});
},
'buildModals': function() {
var modals = [{
'id': 'terms'
}];
App.collections.modalCollection = new Collections.ModalCollection(modals);
},
'applyClass': function(params) {
this.$el.attr('class', params.id);
},
'updateRoute': function(e) {
App.routers.appRouter.navigate($(e.currentTarget).attr('href'), {
'trigger': true
});
},
'renderModal': function(id) {
App.views.modalView = new Views.ModalView({
'model': App.collections.modalCollection.get(id)
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment