Skip to content

Instantly share code, notes, and snippets.

@rjz
Created December 9, 2012 22:34
Show Gist options
  • Select an option

  • Save rjz/4247313 to your computer and use it in GitHub Desktop.

Select an option

Save rjz/4247313 to your computer and use it in GitHub Desktop.
Yet Another Backbone Application
(function (window) {
var app = {
defaults: {
layout: "#layout"
},
init: function (opts) {
var options = _.extend({}, this.defaults, opts);
var template = $(options.layout).text();
this.$layout = $(template).appendTo('body');
for (key in this.data) {
this.data[key] = new this[key].Collection(this.data[key]);
}
for (key in this) {
if (this[key].Router) {
new (this[key].Router);
}
}
Backbone.history.start();
},
bootstrap: function (key, val) {
this.data = this.data || {};
this.data[key] = val;
},
show: function (selector, view) {
this.$layout.find(selector).empty().append(view.el);
},
navigate: function (path) {
this.trigger('app:navigate', path);
Backbone.history.navigate(path, { trigger: true });
}
};
_.extend(app, Backbone.Events);
window.Application = app;
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment