]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Implement instance method on the bridge to return widget instance - Fixes...
authorCorey Frang <gnarf@gnarf.net>
Wed, 30 Jan 2013 14:11:22 +0000 (08:11 -0600)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 19 Mar 2013 15:07:59 +0000 (16:07 +0100)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 8102b1f4fa84d8ffda6ded4c5d9daf8005b091b4..0f6692c3c71fff55ccdba72bac1b66c9711f5ca2 100644 (file)
@@ -625,6 +625,19 @@ test( ".widget() - overriden", function() {
        deepEqual( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] );
 });
 
+test( ".instance()", function() {
+       expect( 1 );
+       var div,
+               _test = function() {};
+
+       $.widget( "ui.testWidget", {
+               _create: function() {},
+               _test: _test
+       });
+       div = $( "<div>" ).testWidget();
+       equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) );
+});
+
 test( "._on() to element (default)", function() {
        expect( 12 );
        var that, widget;
index adc4b9da1bf884bc2097f7e228d9d30179b25f73..ca097e02bc6c7dc3d1db24225408eb260a6098cb 100644 (file)
@@ -182,6 +182,10 @@ $.widget.bridge = function( name, object ) {
                                        return $.error( "cannot call methods on " + name + " prior to initialization; " +
                                                "attempted to call method '" + options + "'" );
                                }
+                               if ( options === "instance" ) {
+                                       returnValue = instance;
+                                       return false;
+                               }
                                if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
                                        return $.error( "no such method '" + options + "' for " + name + " widget instance" );
                                }