From 36cb6f264dbe6b155f8fd97b0ee7615a0f1adedb Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Wed, 30 Jan 2013 08:11:22 -0600 Subject: [PATCH] Widget: Implement instance method on the bridge to return widget instance - Fixes #9030 - `instance` method in widget prototype --- tests/unit/widget/widget_core.js | 13 +++++++++++++ ui/jquery.ui.widget.js | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 8102b1f4f..0f6692c3c 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -625,6 +625,19 @@ test( ".widget() - overriden", function() { deepEqual( wrapper[0], $( "
" ).testWidget().testWidget( "widget" )[0] ); }); +test( ".instance()", function() { + expect( 1 ); + var div, + _test = function() {}; + + $.widget( "ui.testWidget", { + _create: function() {}, + _test: _test + }); + div = $( "
" ).testWidget(); + equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) ); +}); + test( "._on() to element (default)", function() { expect( 12 ); var that, widget; diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index adc4b9da1..ca097e02b 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -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" ); } -- 2.39.5