Skip to content

Commit

Permalink
Widget: Added ability to use $.widget() to create extensions. Fixes #…
Browse files Browse the repository at this point in the history
…6937 - Widget: Allow redefining a widget to create extensions.
  • Loading branch information
scottgonzalez committed Feb 3, 2011
1 parent ed49033 commit ee88a56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tests/unit/widget/widget_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,4 +821,25 @@ test( "auto-destroy - .detach()", function() {
$( "#widget" ).testWidget().detach();
});

test( "redefine", function() {
expect( 4 );
$.widget( "ui.testWidget", {
method: function( str ) {
strictEqual( this, instance, "original invoked with correct this" );
equal( str, "bar", "original invoked with correct parameter" );
}
});
var ctor = $.ui.testWidget;
$.widget( "ui.testWidget", $.ui.testWidget, {
method: function( str ) {
equal( str, "foo", "new invoked with correct parameter" );
this._super( "method", "bar" );
}
});

var instance = new $.ui.testWidget();
instance.method( "foo" );
equal( $.ui.testWidget, ctor, "constructor did not change" );
});

}( jQuery ) );
2 changes: 1 addition & 1 deletion ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $.widget = function( name, base, prototype ) {
};

$[ namespace ] = $[ namespace ] || {};
$[ namespace ][ name ] = function( options, element ) {
$[ namespace ][ name ] = $[ namespace ][ name ] || function( options, element ) {
// allow instantiation without "new" keyword
if ( !this._createWidget ) {
return new $[ namespace ][ name ]( options, element );
Expand Down

0 comments on commit ee88a56

Please sign in to comment.