Skip to content

Instantly share code, notes, and snippets.

@edfuh
Forked from tbranyen/useLayout.js
Created June 4, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edfuh/5708266 to your computer and use it in GitHub Desktop.
Save edfuh/5708266 to your computer and use it in GitHub Desktop.
// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"": "index"
},
index: function() {
this.useLayout("main").setViews({
header: new UI.Views.Toolbar()
}).render();
},
// Helper for specific layouts.
useLayout: function(name) {
// If already using this Layout, then don't re-inject into the DOM.
if (this.layout && this.layout.options.template === name) {
return this.layout;
}
// Ensure previous layouts are completely removed.
if (this.layout) {
this.layout.remove();
}
// Create a new Layout.
var layout = new Backbone.Layout({
template: name,
className: "layout " + name,
id: "layout"
});
// Insert into the DOM.
$("#main").empty().append(layout.el);
// Render the layout.
layout.render();
// Cache the reference on the Router.
this.layout = layout;
// Return the reference, for later usage.
return layout;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment