Created
May 22, 2013 19:04
Revisions
-
mikecx created this gist
May 22, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ // Mix regions into Backbone Views that don't have them. var Mixins = { Regions: {} }; Mixins.Regions = function (parent) { var initialize = parent.prototype.initialize, render = parent.prototype.render, close = parent.prototype.close, functions = ['addRegion', 'addRegions', 'removeRegion', '_buildRegions', '_initializeRegions', '_reInitializeRegions', '_initRegionManager']; parent.prototype.initialize = function (options) { for(var func in functions) { parent.prototype[functions[func]] = Backbone.Marionette.Layout.prototype[functions[func]]; }; initialize.apply(this, arguments); this._firstRender = true; this._initializeRegions(options); }; parent.prototype.render = function () { render.apply(this, arguments); if (this._firstRender){ // if this is the first render, don't do anything to // reset the regions this._firstRender = false; } else if (this.isClosed){ // a previously closed layout means we need to // completely re-initialize the regions this._initializeRegions(); } else { // If this is not the first render call, then we need to // re-initializing the `el` for each region this._reInitializeRegions(); } }; parent.prototype.close = function () { if (this.isClosed){ return; } this.regionManager.close(); close.apply(this, arguments); } };