]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget Bridge: Make the _init method optional. Add tests for both states. Fixes ... 1078/head
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Wed, 11 Sep 2013 20:11:58 +0000 (22:11 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Wed, 11 Sep 2013 20:26:34 +0000 (22:26 +0200)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 3db79ec06b368e531d3c406586ffd996113498dc..ec4c8587489ad4ad53f7f68ab95ee5b7cf837c9a 100644 (file)
@@ -1409,7 +1409,7 @@ asyncTest( "_delay", function() {
 });
 
 test( "$.widget.bridge()", function() {
-       expect( 10 );
+       expect( 14 );
 
        var instance, ret,
                elem = $( "<div>" );
@@ -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() {
index 885e2019f4016ac225c1e296add6eea5fe339a84..b4aab5f3e2f7811146a67dd86a703d78cf441924 100644 (file)
@@ -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 ) );
                                }