-
-
Save mstapp/9452045 to your computer and use it in GitHub Desktop.
blog - attach view to html
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
// attach to static html at element "#navbar-links" | |
var myview = new MyView( {el: $('#navbar-links')} ); |
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
<nav class="navbar navbar-default" role="navigation"> | |
<div class="container-fluid"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#">My Application</a> | |
</div> | |
<div class="collapse navbar-collapse" id="navbar-links"> | |
<ul class="nav navbar-nav"> | |
<li class="active"><a href="#">Monkeys</a></li> | |
<li><a href="#gorillas">Gorillas</a></li> | |
</ul> | |
</div> | |
</div> | |
</nav> |
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
Module.Controller = Marionette.Controller.extend({ | |
start: function(){ | |
this.view = new Module.View( {el: $('#navbar-links')} ); // attach to static html @ that element | |
} | |
}); | |
Module.View = Marionette.ItemView.extend({ | |
// override: don't really render, since this view just attaches to existing navbar html. | |
render: function() { | |
} | |
}); |
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
Module.View = Marionette.ItemView.extend({ | |
events: { | |
'click a': 'onClickLink', | |
}, | |
onClickLink: function(e) { | |
this.$('li.active').toggleClass('active', false); // turn previously-selected nav link off | |
$(e.target).blur() | |
.closest('li').toggleClass('active', true); // turn on new link | |
}, | |
// custom render: don't really render, since this view just attaches to existing navbar html. | |
render: function() { | |
}, | |
}); |
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
// override: don't really render, since this view just attaches to existing navbar html. | |
render: function() { | |
this.bindUIElements(); // wire up this.ui, if any. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment