Skip to content

Instantly share code, notes, and snippets.

@robertcasanova
Last active December 10, 2015 03:18
Show Gist options
  • Select an option

  • Save robertcasanova/4373260 to your computer and use it in GitHub Desktop.

Select an option

Save robertcasanova/4373260 to your computer and use it in GitHub Desktop.
Custom events and subviews with Backbone
App.SidebarView = Backbone.View.extend({
toggle: function() {
if ($(this.el).is(':visible')) {
$(this.el).hide();
this.trigger('collapse'); // <==
} else {
$(this.el).show();
this.trigger('expand'); // <==
}
},
});
App.ChromeView = Backbone.View.extend({
render: function() {
this.sidebar = new App.SidebarView({ el: this.$(".sidebar") });
this.sidebar
.bind('collapse', this.onSidebarCollapse)
.bind('expand', this.onSidebarExpand);
// ...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment