Skip to content

Commit

Permalink
First draft for a $.Widget _super method
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Jun 17, 2010
1 parent aa416fc commit 30d468d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
17 changes: 17 additions & 0 deletions tests/unit/widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,21 @@ test(".widget() - overriden", function() {
same(wrapper[0], $("<div></div>").testWidget().testWidget("widget")[0]);
});

test("_super", function() {
expect(2);
$.widget("sup.parent", {
log: function() {
ok( this.called );
}
});
$.widget("sup.child", $.sup.parent, {
log: function() {
this.called = true;
ok( true );
this._super("log");
}
});
$("<div></div>").child().child("log");
});

})(jQuery);
2 changes: 1 addition & 1 deletion ui/jquery.ui.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $.widget( "ui.autocomplete", {
.removeAttr( "aria-autocomplete" )
.removeAttr( "aria-haspopup" );
this.menu.element.remove();
$.Widget.prototype.destroy.call( this );
this._super( "destroy" );
},

_setOption: function( key ) {
Expand Down
4 changes: 2 additions & 2 deletions ui/jquery.ui.button.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ $.widget( "ui.button", {
this.buttonElement.removeAttr( "title" );
}

$.Widget.prototype.destroy.call( this );
this._super( "destroy" );
},

_setOption: function( key, value ) {
Expand Down Expand Up @@ -358,7 +358,7 @@ $.widget( "ui.buttonset", {
.end()
.button( "destroy" );

$.Widget.prototype.destroy.call( this );
this._super( "destroy" );
}
});

Expand Down
9 changes: 7 additions & 2 deletions ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ $.widget = function( name, base, prototype ) {
namespace: namespace,
widgetName: name,
widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
widgetBaseClass: fullName
widgetBaseClass: fullName,
base: base.prototype
}, prototype );

$.widget.bridge( name, $[ namespace ][ name ] );
Expand Down Expand Up @@ -145,7 +146,11 @@ $.Widget.prototype = {
},
_create: function() {},
_init: function() {},


_super: function( method ) {
this.base[ method ].apply( this, $.makeArray( arguments ).slice( 1 ) );
},

destroy: function() {
this.element
.unbind( "." + this.widgetName )
Expand Down

0 comments on commit 30d468d

Please sign in to comment.