Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Last active December 21, 2015 00:59
Show Gist options
  • Save codeimpossible/6224725 to your computer and use it in GitHub Desktop.
Save codeimpossible/6224725 to your computer and use it in GitHub Desktop.
example interaction between a module and a common header layout in a backbone app...
App.Views.HeaderLayout = Marionette.Layout.extend({
Controller: Marionette.Controller.extend({
addMenu: function( menuView ) {
this.trigger( 'menu:add', menuView );
}
}),
menus: 0,
initialize: function() {
var controller = App.headerController = ( App.headerController || new this.Controller() );
this.listenTo( controller, 'menu:add' this.drawMenu, this );
},
drawMenu: function( menuView ) {
var $menuContainer = $( 'li', { 'class': 'dropdown' } );
var region = this.regionManager.addRegion( 'menu' + (++this.menus), $menuContainer );
region.show( menuView );
}
});
// in an initializer for our module...
app.ModuleExample.addInitializer( function() {
App.headerController.addMenu( new app.ModuleExample.Views.HeaderMenu() );
});
<a href="#projects" class="dropdown-toggle">Projects<b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#projects/myprojects">My Teams' Projects</a></li>
<li class="divider"></li>
<li class="nav-header">Recent Projects</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment