Skip to content

Commit

Permalink
Merge pull request #212 from hull/feature/default_options
Browse files Browse the repository at this point in the history
Allow default options hash for widgets
  • Loading branch information
sbellity committed Mar 8, 2013
2 parents 935928e + 26e40c3 commit 9a09c2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ext/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define('aura/ext/widgets', function() {
return function(app) {

var core = app.core;
var _ = app.core.util._;
core.Widgets = core.Widgets || {};

var ownProp = function(obj, key) {
Expand All @@ -23,11 +24,11 @@ define('aura/ext/widgets', function() {
* @param {Object} options the options to init the widget...
*/
function Widget(options) {
this.options = options;
this.options = _.defaults(options || {}, this.options || {});
this._ref = options._ref;
this.$el = core.dom.find(options.el);

this.initialize.call(this, options);
this.initialize.call(this, this.options);
return this;
}

Expand Down
7 changes: 7 additions & 0 deletions spec/lib/ext/widgets_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ define(['aura/aura', 'aura/ext/widgets'], function (aura, ext) {
var app, options;

var myAltWidget = makeSpyWidget('alt_namespace', {
options: {
foo: 'bar',
another: 'toutafait'
},
initialize: function () {
options = this.options;
}
Expand All @@ -77,6 +81,7 @@ define(['aura/aura', 'aura/ext/widgets'], function (aura, ext) {
var markup = '<div ' +
' data-super-widget="alt_namespace" ' +
' data-super-param-name="value" ' +
' data-super-foo="notbar" ' +
' data-super-sourceUrl="url" ' +
' data-super-fuNNy-Case-PaRAm="yep" ' +
' data-super-param_name-With-un_der_scores="underscore"' +
Expand All @@ -95,6 +100,8 @@ define(['aura/aura', 'aura/ext/widgets'], function (aura, ext) {
});

it('It should take the right options too...', function () {
options.another.should.equal('toutafait');
options.foo.should.equal('notbar');
options.sourceurl.should.equal('url');
options.paramName.should.equal('value');
options.funnyCaseParam.should.equal('yep');
Expand Down

0 comments on commit 9a09c2f

Please sign in to comment.