Skip to content

Instantly share code, notes, and snippets.

@koenpunt
Created February 21, 2013 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenpunt/5005063 to your computer and use it in GitHub Desktop.
Save koenpunt/5005063 to your computer and use it in GitHub Desktop.
Very asic view manager for Backbone.js
/**
*
* Basic view manager
*
* var viewManager = new ViewManager({
* container: '#container'
* });
*
**/
// Extend Backbone.View with a close function, which removes the
// view from the DOM and unbinds the events
_.extend(Backbone.View.prototype, {
close: function(){
this.remove();
this.unbind();
}
});
(function(){
var ViewManager = (function(){
function ViewManager(options){
this.currentView = null;
this.$container = $(options.container);
};
ViewManager.prototype = {
showView: function(view){
if(this.currentView){
this.currentView.close();
}
this.currentView = view;
this.currentView.render();
this.$container.html(this.currentView.el);
}
};
return ViewManager;
})();
this.ViewManager = ViewManager;
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment