Skip to content

Commit

Permalink
Widget: Maintain stack when a method returns a jQuery object. Fixes #…
Browse files Browse the repository at this point in the history
…5732 - Widget: Make the widget method maintain the stack.
  • Loading branch information
scottgonzalez committed Mar 22, 2011
1 parent e7991e3 commit f772240
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions tests/unit/widget/widget_core.js
Expand Up @@ -74,7 +74,7 @@ test( "element normalization", function() {
});

test( "jQuery usage", function() {
expect( 11 );
expect( 13 );

var shouldCreate = false;

Expand All @@ -98,6 +98,9 @@ test( "jQuery usage", function() {
} else {
return this.getterSetterVal;
}
},
jQueryObject: function() {
return $( "body" );
}
});

Expand All @@ -120,6 +123,9 @@ test( "jQuery usage", function() {
ret = elem.testWidget( "getterSetterMethod", 30 );
equals( ret, elem, "getter/setter method can be chainable" );
equals( instance.getterSetterVal, 30, "getter/setter can act as setter" );
ret = elem.testWidget( "jQueryObject" );
equal( ret[ 0 ], document.body, "returned jQuery object" );
equal( ret.end(), elem, "stack preserved" );
});

test( "direct usage", function() {
Expand Down Expand Up @@ -765,7 +771,7 @@ test( "._trigger() - provide event and ui", function() {
.testWidget( "testEvent" );
});

test( "._triger() - instance as element", function() {
test( "._trigger() - instance as element", function() {
expect( 4 );
$.widget( "ui.testWidget", {
defaultElement: null,
Expand Down
4 changes: 3 additions & 1 deletion ui/jquery.ui.widget.js
Expand Up @@ -116,7 +116,9 @@ $.widget.bridge = function( name, object ) {
}
var methodValue = instance[ options ].apply( instance, args );
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue;
returnValue = methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
methodValue;
return false;
}
});
Expand Down

0 comments on commit f772240

Please sign in to comment.