Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created July 25, 2015 19:00
Show Gist options
  • Save MeoMix/22237e7965e1e4ed2fa8 to your computer and use it in GitHub Desktop.
Save MeoMix/22237e7965e1e4ed2fa8 to your computer and use it in GitHub Desktop.
define(function(require) {
'use strict';
require('backbone.marionette');
Marionette.Region.buildRegion = function(regionConfig, DefaultRegionClass) {
if (_.isString(regionConfig)) {
regionConfig = '[data-region=' + regionConfig + ']';
return this._buildRegionFromSelector(regionConfig, DefaultRegionClass);
}
if (regionConfig.selector || regionConfig.el || regionConfig.regionClass) {
if (regionConfig.selector) {
regionConfig.selector = '[data-region=' + regionConfig.selector + ']';
}
if (regionConfig.el) {
regionConfig.el = '[data-region=' + regionConfig.el + ']';
}
return this._buildRegionFromObject(regionConfig, DefaultRegionClass);
}
if (_.isFunction(regionConfig)) {
return this._buildRegionFromRegionClass(regionConfig);
}
throw new Marionette.Error({
message: 'Improper region configuration type.',
url: 'marionette.region.html#region-configuration-types'
});
};
});
define(function(require) {
'use strict';
require('backbone.marionette');
Marionette.View.prototype.useCustomUiSelector = false;
Marionette.View.prototype._bindUIElements = function() {
if (!this.ui) { return; }
// store the ui hash in _uiBindings so they can be reset later
// and so re-rendering the view will be able to find the bindings
if (!this._uiBindings) {
this._uiBindings = this.ui;
}
// get the bindings result, as a function or otherwise
var bindings = _.result(this, '_uiBindings');
// empty the ui so we don't have anything to start with
this.ui = {};
// bind each of the selectors
_.each(bindings, function(selector, key) {
selector = this.useCustomUiSelector ? selector : '[data-ui~=' + selector + ']';
this.ui[key] = this.$(selector);
}, this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment