Skip to content
Permalink
Browse files

Widget: Allow redefining a widget after other widgets have inherited …

…from it.
  • Loading branch information...
scottgonzalez committed Feb 1, 2012
1 parent e496cde commit 8cd4a8330ca79f222e193de585e2746b4ad3500d
Showing with 217 additions and 168 deletions.
  1. +5 −5 tests/unit/tabs/tabs_deprecated.js
  2. +44 −1 tests/unit/widget/widget_core.js
  3. +119 −137 ui/jquery.ui.tabs.js
  4. +49 −25 ui/jquery.ui.widget.js
@@ -281,7 +281,7 @@ test( "enable", function() {

var element = $( "#tabs1" ).tabs({
disabled: [ 0, 1 ],
enable: function ( event, ui ) {
enable: function( event, ui ) {
equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
equals( ui.index, 1, "ui.index" );
@@ -296,10 +296,10 @@ test( "disable", function() {
expect( 3 );

var element = $( "#tabs1" ).tabs({
disable: function ( event, ui ) {
equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
equals( ui.index, 1, "ui.index" );
disable: function( event, ui ) {
equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" );
equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" );
equals( ui.index, 1, "ui.index" );
}
});
element.tabs( "disable", 1 );
@@ -1050,11 +1050,54 @@ test( "redefine", function() {
}
});

var instance = new $.ui.testWidget();
var instance = new $.ui.testWidget({});
instance.method( "foo" );
equal( $.ui.testWidget.foo, "bar", "static properties remain" );
});

test( "redefine deep prototype chain", function() {
expect( 8 );
$.widget( "ui.testWidget", {
method: function( str ) {
strictEqual( this, instance, "original invoked with correct this" );
equal( str, "level 4", "original invoked with correct parameter" );
}
});
$.widget( "ui.testWidget2", $.ui.testWidget, {
method: function( str ) {
strictEqual( this, instance, "testWidget2 invoked with correct this" );
equal( str, "level 2", "testWidget2 invoked with correct parameter" );
this._super( "level 3" );
}
});
$.widget( "ui.testWidget3", $.ui.testWidget2, {
method: function( str ) {
strictEqual( this, instance, "testWidget3 invoked with correct this" );
equal( str, "level 1", "testWidget3 invoked with correct parameter" );
this._super( "level 2" );
}
});
// redefine testWidget after other widgets have inherited from it
// this tests whether the inheriting widgets get updated prototype chains
$.widget( "ui.testWidget", $.ui.testWidget, {
method: function( str ) {
strictEqual( this, instance, "new invoked with correct this" );
equal( str, "level 3", "new invoked with correct parameter" );
this._super( "level 4" );
}
});
// redefine testWidget3 after it has been automatically redefined
// this tests whether we properly handle _super() when the topmost prototype
// doesn't have the method defined
$.widget( "ui.testWidget3", $.ui.testWidget3, {} );

var instance = new $.ui.testWidget3({});
instance.method( "level 1" );

delete $.ui.testWidget3;
delete $.ui.testWidget2;
});

asyncTest( "_delay", function() {
expect( 6 );
var order = 0,

0 comments on commit 8cd4a83

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