Created
December 12, 2011 17:21
-
-
Save mxriverlynn/1468250 to your computer and use it in GitHub Desktop.
Regions and Region Managers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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