Skip to content

Commit 6e799c3

Browse files
committed
Widget Bridge: Make the _init method optional. Add tests for both states. Fixes #9543 - Widget bridge: Make _init() optional.
1 parent 37bba1e commit 6e799c3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tests/unit/widget/widget_core.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ asyncTest( "_delay", function() {
14091409
});
14101410

14111411
test( "$.widget.bridge()", function() {
1412-
expect( 10 );
1412+
expect( 14 );
14131413

14141414
var instance, ret,
14151415
elem = $( "<div>" );
@@ -1427,6 +1427,9 @@ test( "$.widget.bridge()", function() {
14271427
},
14281428
getter: function() {
14291429
return "qux";
1430+
},
1431+
option: function( options ) {
1432+
deepEqual( options, {} );
14301433
}
14311434
});
14321435

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

14451448
ret = elem.testWidget( "getter" );
14461449
equal( ret, "qux", "getter returns value" );
1450+
1451+
elem.testWidget();
1452+
ok( true, "_init is optional" );
1453+
1454+
TestWidget.prototype._init = function() {
1455+
ok( "_init", "_init now exists, so its called" );
1456+
};
1457+
elem.testWidget();
14471458
});
14481459

14491460
test( "$.widget.bridge() - widgetFullName", function() {

ui/jquery.ui.widget.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ $.widget.bridge = function( name, object ) {
203203
this.each(function() {
204204
var instance = $.data( this, fullName );
205205
if ( instance ) {
206-
instance.option( options || {} )._init();
206+
instance.option( options || {} );
207+
if ( instance._init ) {
208+
instance._init();
209+
}
207210
} else {
208211
$.data( this, fullName, new object( options, this ) );
209212
}

0 commit comments

Comments
 (0)