Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created December 12, 2011 17:21
Show Gist options
  • Select an option

  • Save mxriverlynn/1468250 to your computer and use it in GitHub Desktop.

Select an option

Save mxriverlynn/1468250 to your computer and use it in GitHub Desktop.
Regions and Region Managers
RegionManager = (function (Backbone, $) {
var currentView;
var el = "#mainregion";
var region = {};
var closeView = function (view) {
if (view && view.close) {
view.close();
}
};
var openView = function (view) {
view.render();
$(el).html(view.el);
if (view.onShow) {
view.onShow();
}
};
region.show = function (view) {
closeView(currentView);
currentView = view;
openView(currentView);
};
return region;
})(Backbone, jQuery);
MyView = Backbone.View.extend({
render: function(){
$(this.el).html("some html contents");
$(this.el).hide();
},
close: function(){
this.remove();
this.unbind();
},
onShow: function(){
$(this.el).show(500);
}
});
RegionManager.show(new MyView());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment