aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-02-03 16:37:17 -0500
committerScott González <scott.gonzalez@gmail.com>2011-02-03 16:37:17 -0500
commitee88a562433e75a0dd500ed7c71376d279eaacdf (patch)
treeadd7d9669cf4d41a04005b04c312749b867d5b38
parented4903370090c5e81a5be7a9e23f351fc1b062a6 (diff)
downloadjquery-ui-ee88a562433e75a0dd500ed7c71376d279eaacdf.tar.gz
jquery-ui-ee88a562433e75a0dd500ed7c71376d279eaacdf.zip
Widget: Added ability to use $.widget() to create extensions. Fixes #6937 - Widget: Allow redefining a widget to create extensions.
-rw-r--r--tests/unit/widget/widget_core.js21
-rw-r--r--ui/jquery.ui.widget.js2
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js
index 6f4930621..186c407ed 100644
--- a/tests/unit/widget/widget_core.js
+++ b/tests/unit/widget/widget_core.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 ) );
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 1ec934469..6b84f7a9c 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -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 );