From 6e799c39d33be8eee02224d2f754dc42228a4cbb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Wed, 11 Sep 2013 22:11:58 +0200 Subject: [PATCH] Widget Bridge: Make the _init method optional. Add tests for both states. Fixes #9543 - Widget bridge: Make _init() optional. --- tests/unit/widget/widget_core.js | 13 ++++++++++++- ui/jquery.ui.widget.js | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 3db79ec06..ec4c85874 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -1409,7 +1409,7 @@ asyncTest( "_delay", function() { }); test( "$.widget.bridge()", function() { - expect( 10 ); + expect( 14 ); var instance, ret, elem = $( "
" ); @@ -1427,6 +1427,9 @@ test( "$.widget.bridge()", function() { }, getter: function() { return "qux"; + }, + option: function( options ) { + deepEqual( options, {} ); } }); @@ -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() { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 885e2019f..b4aab5f3e 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -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 ) ); } -- 2.39.5