Last active
December 30, 2015 20:29
-
-
Save jblashill/7880741 to your computer and use it in GitHub Desktop.
When working with backbone, marionette and twitter bootstrap, often I want to create a Marionette.Layout that maps a Twitter bootstrap row. Here's a simple function to generate a Layout from column sizes + names.
This file contains 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
var bootstrapRow = function(cols, names) { | |
var snippets = _.map(cols, function(col) { | |
return "<div class='col-md-" + col + "'></div>"; | |
}); | |
var regions = {}; | |
_.each(names, function(name, index) { | |
regions[name] = ">:nth-child(" + (index+1) + ")"; | |
}); | |
var GridLayout = Backbone.Marionette.Layout.extend({ | |
className: "row", | |
template: _.template(snippets.join("")), | |
regions: regions | |
}); | |
return new GridLayout(); | |
}; | |
// ... example usage: | |
var rowView = bootstrapRow([4, 8], ["sidebar", "content"]); | |
$(document.body).append(rowView.el); | |
rowView.render(); | |
rowView.sidebar.show(mySidebarView); | |
rowView.content.show(myContentView); | |
This file contains 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
<!-- DOM generated by bootstrap row layout view --> | |
<div class="row"> | |
<div class="col-md-4"> | |
<!-- mySideBarView DOM --> | |
</div> | |
<div class="col-md-8"> | |
<!-- myContentView DOM --> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment