Skip to content

Instantly share code, notes, and snippets.

@toddself
Created December 6, 2012 03:51
Show Gist options
  • Save toddself/4221647 to your computer and use it in GitHub Desktop.
Save toddself/4221647 to your computer and use it in GitHub Desktop.
region manager
(function($, _){
var Region = function(el){
this.el = el;
this.$el = $(el);
};
_.extend(Region.prototype, {
show: function(view){
// clean up...
this.clear();
this.view = view;
// set up
var that = this;
var show_dfd = $.Deferred();
// render and resolve
$.when(view.render()).then(function(){
that.$el.html(view.el);
show_dfd.resolve();
});
return show_dfd;
},
clear: function(){
if(this.view){
this.view.undelegateEvents();
this.view.off();
this.view.close();
delete this.view;
}
this.$el.empty();
}
});
window.Region = Region;
})(jQuery, _);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment