Skip to content
Permalink
Browse files

Widget: Added ability to define how to find options on init. Fixes #6…

…158 - Widget: Ability to define new methods for gathering options on init.
  • Loading branch information
scottgonzalez committed Oct 6, 2010
1 parent c3b282f commit 512825d358851f4b2b584f1b6463e9cd48f31752
Showing with 34 additions and 1 deletion.
  1. +26 −0 tests/unit/widget/widget_core.js
  2. +8 −1 ui/jquery.ui.widget.js
@@ -156,6 +156,32 @@ test("merge multiple option arguments", function() {
});
});

test( "_getCreateOptions()", function() {
expect( 1 );
$.widget( "ui.testWidget", {
options: {
option1: "valuex",
option2: "valuex",
option3: "value3",
},
_getCreateOptions: function() {
return {
option1: "override1",
option2: "overideX",
};
},
_create: function() {
same( this.options, {
disabled: false,
option1: "override1",
option2: "value2",
option3: "value3"
});
}
});
$( "<div>" ).testWidget({ option2: "value2" });
});

test( "re-init", function() {
var div = $( "<div></div>" ),
actions = [];
@@ -145,7 +145,7 @@ $.Widget.prototype = {
this.element = $( element );
this.options = $.extend( true, {},
this.options,
$.metadata && $.metadata.get( element )[ this.widgetName ],
this._getCreateOptions(),
options );

var self = this;
@@ -157,6 +157,13 @@ $.Widget.prototype = {
this._trigger( "create" );
this._init();
},
_getCreateOptions: function() {
var options = {};
if ( $.metadata ) {
options = $.metadata.get( element )[ this.widgetName ];
}
return options;
},
_create: function() {},
_init: function() {},

1 comment on commit 512825d

@jzaefferer

This comment has been minimized.

Copy link
Member

jzaefferer commented on 512825d Oct 6, 2010

Why not just return $.metadata && $.metadata.get( element )[ this.widgetName ]? If $.metadata is undefined, returning undefined is fine anyway. $.extend doesn't care.

Please sign in to comment.
You can’t perform that action at this time.