Skip to content

Commit

Permalink
Widget Bridge: Make the _init method optional. Add tests for both sta…
Browse files Browse the repository at this point in the history
…tes. Fixes #9543 - Widget bridge: Make _init() optional.
  • Loading branch information
jzaefferer committed Sep 11, 2013
1 parent 37bba1e commit 6e799c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion tests/unit/widget/widget_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ asyncTest( "_delay", function() {
});

test( "$.widget.bridge()", function() {
expect( 10 );
expect( 14 );

var instance, ret,
elem = $( "<div>" );
Expand All @@ -1427,6 +1427,9 @@ test( "$.widget.bridge()", function() {
},
getter: function() {
return "qux";
},
option: function( options ) {
deepEqual( options, {} );
}
});

Expand All @@ -1444,6 +1447,14 @@ test( "$.widget.bridge()", function() {

ret = elem.testWidget( "getter" );
equal( ret, "qux", "getter returns value" );

elem.testWidget();
ok( true, "_init is optional" );

TestWidget.prototype._init = function() {
ok( "_init", "_init now exists, so its called" );
};
elem.testWidget();
});

test( "$.widget.bridge() - widgetFullName", function() {
Expand Down
5 changes: 4 additions & 1 deletion ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ $.widget.bridge = function( name, object ) {
this.each(function() {
var instance = $.data( this, fullName );
if ( instance ) {
instance.option( options || {} )._init();
instance.option( options || {} );
if ( instance._init ) {
instance._init();
}
} else {
$.data( this, fullName, new object( options, this ) );
}
Expand Down

0 comments on commit 6e799c3

Please sign in to comment.