Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 512825d358851f4b2b584f1b6463e9cd48f31752 1 parent c3b282f
@scottgonzalez scottgonzalez authored
Showing with 34 additions and 1 deletion.
  1. +26 −0 tests/unit/widget/widget_core.js
  2. +8 −1 ui/jquery.ui.widget.js
View
26 tests/unit/widget/widget_core.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 = [];
View
9 ui/jquery.ui.widget.js
@@ -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
Owner

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.
Something went wrong with that request. Please try again.