-
-
Save edfuh/5708266 to your computer and use it in GitHub Desktop.
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
// 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