Skip to content

Commit

Permalink
Widget: Implement instance method on the bridge to return widget inst…
Browse files Browse the repository at this point in the history
…ance - Fixes #9030 - `instance` method in widget prototype
  • Loading branch information
gnarf authored and jzaefferer committed Mar 19, 2013
1 parent f2e45f5 commit 36cb6f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/unit/widget/widget_core.js
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions ui/jquery.ui.widget.js
Expand Up @@ -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" );
}
Expand Down

0 comments on commit 36cb6f2

Please sign in to comment.