Skip to content
Permalink
Browse files

Widget: Added ability to use $.widget() to create extensions. Fixes #…

…6937 - Widget: Allow redefining a widget to create extensions.
  • Loading branch information...
scottgonzalez committed Feb 3, 2011
1 parent ed49033 commit ee88a562433e75a0dd500ed7c71376d279eaacdf
Showing with 22 additions and 1 deletion.
  1. +21 −0 tests/unit/widget/widget_core.js
  2. +1 −1 ui/jquery.ui.widget.js
@@ -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 ) );
@@ -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 );

0 comments on commit ee88a56

Please sign in to comment.
You can’t perform that action at this time.