Skip to content

Instantly share code, notes, and snippets.

@flemdizzle
Created December 1, 2014 18:53
Show Gist options
  • Save flemdizzle/0cf3d49ad235042e7bd6 to your computer and use it in GitHub Desktop.
Save flemdizzle/0cf3d49ad235042e7bd6 to your computer and use it in GitHub Desktop.
var FluffyRouter = Backbone.Router.extend({
routes: {
'seal panda bunny': 'update',
'*default': 'update'
},
update: function(){
var id = Backbone.history.fragment || 'bunny';
$('.view').hide();
$('#' + id).show();
this.navigate(id);
}
});
var NavView = Backbone.View.extend({
el: '#nav',
initialize: function(options){
this.listenTo(options.router, 'route', this.render);
this.render();
},
render: function(){
this.$('a').removeClass('active');
this.$('a[href="#' + Backbone.history.fragment + '"]').addClass('active');
}
});
var router = new FluffyRouter();
var nav = new NavView({router: router});
Backbone.history.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment