Skip to content

Commit 36cb6f2

Browse files
gnarfjzaefferer
authored andcommitted
Widget: Implement instance method on the bridge to return widget instance - Fixes #9030 - instance method in widget prototype
1 parent f2e45f5 commit 36cb6f2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/unit/widget/widget_core.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,19 @@ test( ".widget() - overriden", function() {
625625
deepEqual( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] );
626626
});
627627

628+
test( ".instance()", function() {
629+
expect( 1 );
630+
var div,
631+
_test = function() {};
632+
633+
$.widget( "ui.testWidget", {
634+
_create: function() {},
635+
_test: _test
636+
});
637+
div = $( "<div>" ).testWidget();
638+
equal( div.testWidget( "instance" ), div.data( "ui-testWidget" ) );
639+
});
640+
628641
test( "._on() to element (default)", function() {
629642
expect( 12 );
630643
var that, widget;

ui/jquery.ui.widget.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ $.widget.bridge = function( name, object ) {
182182
return $.error( "cannot call methods on " + name + " prior to initialization; " +
183183
"attempted to call method '" + options + "'" );
184184
}
185+
if ( options === "instance" ) {
186+
returnValue = instance;
187+
return false;
188+
}
185189
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
186190
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
187191
}

0 commit comments

Comments
 (0)