Created
December 9, 2012 22:34
-
-
Save rjz/4247313 to your computer and use it in GitHub Desktop.
Yet Another Backbone Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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