Skip to content

Commit ee88a56

Browse files
committed
Widget: Added ability to use $.widget() to create extensions. Fixes #6937 - Widget: Allow redefining a widget to create extensions.
1 parent ed49033 commit ee88a56

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tests/unit/widget/widget_core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,4 +821,25 @@ test( "auto-destroy - .detach()", function() {
821821
$( "#widget" ).testWidget().detach();
822822
});
823823

824+
test( "redefine", function() {
825+
expect( 4 );
826+
$.widget( "ui.testWidget", {
827+
method: function( str ) {
828+
strictEqual( this, instance, "original invoked with correct this" );
829+
equal( str, "bar", "original invoked with correct parameter" );
830+
}
831+
});
832+
var ctor = $.ui.testWidget;
833+
$.widget( "ui.testWidget", $.ui.testWidget, {
834+
method: function( str ) {
835+
equal( str, "foo", "new invoked with correct parameter" );
836+
this._super( "method", "bar" );
837+
}
838+
});
839+
840+
var instance = new $.ui.testWidget();
841+
instance.method( "foo" );
842+
equal( $.ui.testWidget, ctor, "constructor did not change" );
843+
});
844+
824845
}( jQuery ) );

ui/jquery.ui.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $.widget = function( name, base, prototype ) {
3636
};
3737

3838
$[ namespace ] = $[ namespace ] || {};
39-
$[ namespace ][ name ] = function( options, element ) {
39+
$[ namespace ][ name ] = $[ namespace ][ name ] || function( options, element ) {
4040
// allow instantiation without "new" keyword
4141
if ( !this._createWidget ) {
4242
return new $[ namespace ][ name ]( options, element );

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy