Created
July 25, 2015 19:00
-
-
Save MeoMix/22237e7965e1e4ed2fa8 to your computer and use it in GitHub Desktop.
This file contains 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
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' | |
}); | |
}; | |
}); |
This file contains 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
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