8000 Merge branch 'widget-super' into devpreview · MechanisM/jquery-ui@c665dcc · GitHub
[go: up one dir, main page]

Skip to content

Commit c665dcc

Browse files
committed
Merge branch 'widget-super' into devpreview
2 parents 92723de + e9a2661 commit c665dcc

File tree

8 files changed

+55
-13
lines changed

8 files changed

+55
-13
lines changed

tests/unit/widget/widget.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,37 @@ test(".widget() - overriden", function() {
165165
same(wrapper[0], $("<div></div>").testWidget().testWidget("widget")[0]);
166166
});
167167

168+
test("_super", function() {
169+
expect(2);
170+
$.widget("sup.parent", {
171+
log: function() {
172+
ok( this.called );
173+
}
174+
});
175+
$.widget("sup.child", $.sup.parent, {
176+
log: function() {
177+
this.called = true;
178+
ok( true );
179+
this._super("log");
180+
}
181+
});
182+
$("<div></div>").child().child("log");
183+
});
184+
185+
test("_superApply", function() {
186+
expect(2);
187+
$.widget("sup.parent", {
188+
log: function(a, b) {
189+
same( a, 1 );
190+
same( b, 2 );
191+
}
192+
});
193+
$.widget("sup.child", $.sup.parent, {
194+
log: function() {
195+
this._superApply("log", arguments);
196+
}
197+
});
198+
$("<div></div>").child().child("log", 1, 2);
199+
});
200+
168201
})(jQuery);

ui/jquery.ui.accordion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ $.widget("ui.accordion", {
151151
},
152152

153153
_setOption: function(key, value) {
154-
$.Widget.prototype._setOption.apply(this, arguments);
154+
this._superApply( "_setOption", arguments );
155155

156156
if (key == "active") {
157157
this.activate(value);

ui/jquery.ui.autocomplete.js

Lines changed: 2 additions & 2 deletions
< 8000 div data-testid="deletion diffstat" class="DiffSquares-module__diffSquare--h5kjy DiffSquares-module__deletion--hKV3q">
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ $.widget( "ui.autocomplete", {
166166
.removeAttr( "aria-autocomplete" )
167167
.removeAttr( "aria-haspopup" );
168168
this.menu.element.remove();
169-
$.Widget.prototype.destroy.call( this );
169+
this._super( "destroy" );
170170
},
171171

172172
_setOption: function( key ) {
173-
$.Widget.prototype._setOption.apply( this, arguments );
173+
this._superApply( "_setOption", arguments );
174174
if ( key === "source" ) {
175175
this._initSource();
176176
}

ui/jquery.ui.button.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ $.widget( "ui.button", {
226226
this.buttonElement.removeAttr( "title" );
227227
}
228228

229-
$.Widget.prototype.destroy.call( this );
229+
this._super( "destroy" );
230230
},
231231

232232
_setOption: function( key, value ) {
233-
$.Widget.prototype._setOption.apply( this, arguments );
233+
this._superApply( "_setOption", arguments );
234234
if ( key === "disabled" ) {
235235
if ( value ) {
236236
this.element.attr( "disabled", true );
@@ -324,7 +324,7 @@ $.widget( "ui.buttonset", {
324324
this.buttons.button( "option", key, value );
325325
}
326326

327-
$.Widget.prototype._setOption.apply( this, arguments );
327+
this._superApply( "_setOption", arguments );
328328
},
329329

330330
refresh: function() {
@@ -358,7 +358,7 @@ $.widget( "ui.buttonset", {
358358
.end()
359359
.button( "destroy" );
360360

361-
$.Widget.prototype.destroy.call( this );
361+
this._super( "destroy" );
362362
}
363363
});
364364

ui/jquery.ui.progressbar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $.widget( "ui.progressbar", {
4343

4444
this.valueDiv.remove();
4545

46-
$.Widget.prototype.destroy.apply( this, arguments );
46+
this._superApply( "destroy", arguments );
4747
},
4848

4949
value: function( newValue ) {
@@ -64,7 +64,7 @@ $.widget( "ui.progressbar", {< F438 /div>
6464
break;
6565
}
6666

67-
$.Widget.prototype._setOption.apply( this, arguments );
67+
this._superApply( "_setOption", arguments );
6868
},
6969

7070
_value: function() {

ui/jquery.ui.slider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ $.widget( "ui.slider", $.ui.mouse, {
511511
valsLength = this.options.values.length;
512512
}
513513

514-
$.Widget.prototype._setOption.apply( this, arguments );
514+
this._superApply( "_setOption", arguments );
515515

516516
switch ( key ) {
517517
case "disabled":

ui/jquery.ui.sortable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $.widget("ui.sortable", $.ui.mouse, {
8181
[ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" );
8282
} else {
8383
// Don't call widget base _setOption for disable as it adds ui-state-disabled class
84-
$.Widget.prototype._setOption.apply(this, arguments);
84+
this._superApply( "_setOption", arguments );
8585
}
8686
},
8787

ui/jquery.ui.widget.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ $.widget = function( name, base, prototype ) {
6262
namespace: namespace,
6363
widgetName: name,
6464
widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
65-
widgetBaseClass: fullName
65+
widgetBaseClass: fullName,
66+
base: base.prototype
6667
}, prototype );
6768

6869
$.widget.bridge( name, $[ namespace ][ name ] );
@@ -145,7 +146,15 @@ $.Widget.prototype = {
145146
},
146147
_create: function() {},
147148
_init: function() {},
148-
149+
150+
_super: function( method ) {
151+
return this.base[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) );
152+
},
153+
154+
_superApply: function( method, args ) {
155+
return this.base[ method ].apply( this, args );
156+
},
157+
149158
destroy: function() {
150159
this.element
151160
.unbind( "." + this.widgetName )

0 commit comments

Comments
 (0)
0