Skip to content

Instantly share code, notes, and snippets.

@stephanebachelier
Forked from jasonLaster/foo.diff
Last active August 29, 2015 14:09
Show Gist options
  • Save stephanebachelier/f34871a77d9476dff72f to your computer and use it in GitHub Desktop.
Save stephanebachelier/f34871a77d9476dff72f to your computer and use it in GitHub Desktop.
diff --git a/src/layout-view.js b/src/layout-view.js
index 9c85195..9064053 100644
--- a/src/layout-view.js
+++ b/src/layout-view.js
@@ -16,6 +16,7 @@ Marionette.LayoutView = Marionette.ItemView.extend({
options = options || {};
this._firstRender = true;
+ this._ensureElement();
this._initializeRegions(options);
// At this point since this view's $el is not constructed,
@@ -25,14 +26,14 @@ Marionette.LayoutView = Marionette.ItemView.extend({
// Now that this view's $el is constructed,
// and the regions' 'getEl' method is overridden,
// scope all regions to this view's $el (the parent view).
- this.regionManager.each(function(region) {
- if (!_.isObject(region.el)) {
- region.$el = region.getEl(region.el);
- if (region.$el.length > 0) {
- region.el = region.$el[0];
- }
- }
- });
+ // this.regionManager.each(function(region) {
+ // if (!_.isObject(region.el)) {
+ // region.$el = region.getEl(region.el);
+ // if (region.$el.length > 0) {
+ // region.el = region.$el[0];
+ // }
+ // }
+ // });
},
// LayoutView's render will use the existing region objects the
diff --git a/src/region.js b/src/region.js
index fb5e1c6..1effed0 100644
--- a/src/region.js
+++ b/src/region.js
@@ -274,6 +274,18 @@ Marionette.Region = Marionette.Object.extend({
options.el = regionConfig.selector;
}
+ if (options.el && regionConfig.parentEl) {
+ var parentEl = _.result(regionConfig, 'parentEl');
+
+ var $el = parentEl.find(options.el);
+ if ($el.length > 0) {
+ options.el = $el[0];
+ }
+ }
+
var region = new RegionClass(options);
// override the `getEl` function if we have a parentEl
diff --git a/test/unit/layout-view.spec.js b/test/unit/layout-view.spec.js
index 10b9fd4..36f947c 100644
--- a/test/unit/layout-view.spec.js
+++ b/test/unit/layout-view.spec.js
@@ -470,6 +470,7 @@ describe('layoutView', function() {
regionOne: '.region-one'
}
});
+
this.layoutViewInstance = new this.LayoutView();
var $specNode = $(".region-hash-no-template-spec");
this.$inScopeRegion = $specNode.children(".some-layout-view").children(".region-one");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment