Skip to content

Commit e543253

Browse files
committed
Widget: Remove core event/alias and deprecated module dependencies
1 parent 24f1ce9 commit e543253

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

demos/widget/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
});
140140

141141
// click to toggle enabled/disabled
142-
$( "#disable" ).click(function() {
142+
$( "#disable" ).on( "click", function() {
143143
// use the custom selector created for each widget to find all instances
144144
// all instances are toggled together, so we can check the state from the first
145145
if ( $( ":custom-colorize" ).colorize( "option", "disabled" ) ) {
@@ -150,7 +150,7 @@
150150
});
151151

152152
// click to set options after initialization
153-
$( "#green" ).click( function() {
153+
$( "#green" ).on( "click", function() {
154154
$( ":custom-colorize" ).colorize( "option", {
155155
red: 64,
156156
green: 250,

tests/unit/widget/core.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ test( "jQuery usage", function() {
131131

132132
shouldCreate = true;
133133
elem = $( "<div>" )
134-
.bind( "testwidgetcreate", function() {
134+
.on( "testwidgetcreate", function() {
135135
ok( shouldCreate, "create event triggered on instantiation" );
136136
})
137137
.testWidget();
@@ -902,15 +902,15 @@ test( "_on() with delegate", function() {
902902
_create: function() {
903903
var uuid = this.uuid;
904904
this.element = {
905-
bind: function( event, handler ) {
905+
on: function( event, handler ) {
906906
equal( event, "click.testWidget" + uuid );
907907
ok( $.isFunction(handler) );
908908
},
909909
trigger: $.noop
910910
};
911911
this.widget = function() {
912912
return {
913-
delegate: function( selector, event, handler ) {
913+
on: function( event, selector, handler ) {
914914
equal( selector, "a" );
915915
equal( event, "click.testWidget" + uuid );
916916
ok( $.isFunction(handler) );
@@ -923,7 +923,7 @@ test( "_on() with delegate", function() {
923923
});
924924
this.widget = function() {
925925
return {
926-
delegate: function( selector, event, handler ) {
926+
on: function( event, selector, handler ) {
927927
equal( selector, "form fieldset > input" );
928928
equal( event, "change.testWidget" + uuid );
929929
ok( $.isFunction(handler) );
@@ -1005,7 +1005,7 @@ test( "_off() - single event", function() {
10051005
widget._on( element, { foo: function() {
10061006
ok( shouldTriggerWidget, "foo called from _on" );
10071007
}});
1008-
element.bind( "foo", function() {
1008+
element.on( "foo", function() {
10091009
ok( shouldTriggerOther, "foo called from bind" );
10101010
});
10111011
shouldTriggerWidget = true;
@@ -1031,7 +1031,7 @@ test( "_off() - multiple events", function() {
10311031
ok( shouldTriggerWidget, "bar called from _on" );
10321032
}
10331033
});
1034-
element.bind( "foo bar", function( event ) {
1034+
element.on( "foo bar", function( event ) {
10351035
ok( shouldTriggerOther, event.type + " called from bind" );
10361036
});
10371037
shouldTriggerWidget = true;
@@ -1059,7 +1059,7 @@ test( "_off() - all events", function() {
10591059
ok( shouldTriggerWidget, "bar called from _on" );
10601060
}
10611061
});
1062-
element.bind( "foo bar", function( event ) {
1062+
element.on( "foo bar", function( event ) {
10631063
ok( shouldTriggerOther, event.type + " called from bind" );
10641064
});
10651065
shouldTriggerWidget = true;
@@ -1152,7 +1152,7 @@ test( "._trigger() - no event, no ui", function() {
11521152
}
11531153
});
11541154
$( document ).add( "#widget-wrapper" ).add( "#widget" )
1155-
.bind( "testwidgetfoo", function( event, ui ) {
1155+
.on( "testwidgetfoo", function( event, ui ) {
11561156
deepEqual( ui, {}, "empty ui hash passed" );
11571157
handlers.push( this );
11581158
});
@@ -1165,7 +1165,7 @@ test( "._trigger() - no event, no ui", function() {
11651165
"callback"
11661166
], "event bubbles and then invokes callback" );
11671167

1168-
$( document ).unbind( "testwidgetfoo" );
1168+
$( document ).off( "testwidgetfoo" );
11691169
});
11701170

11711171
test( "._trigger() - cancelled event", function() {
@@ -1180,7 +1180,7 @@ test( "._trigger() - cancelled event", function() {
11801180
ok( true, "callback invoked even if event is cancelled" );
11811181
}
11821182
})
1183-
.bind( "testwidgetfoo", function() {
1183+
.on( "testwidgetfoo", function() {
11841184
ok( true, "event was triggered" );
11851185
return false;
11861186
});
@@ -1227,7 +1227,7 @@ test( "._trigger() - provide event and ui", function() {
12271227
}, "ui object modified" );
12281228
}
12291229
});
1230-
$( "#widget" ).bind( "testwidgetfoo", function( event, ui ) {
1230+
$( "#widget" ).on( "testwidgetfoo", function( event, ui ) {
12311231
equal( event.originalEvent, originalEvent, "original event object passed" );
12321232
deepEqual( ui, {
12331233
foo: "bar",
@@ -1238,7 +1238,7 @@ test( "._trigger() - provide event and ui", function() {
12381238
}, "ui hash passed" );
12391239
ui.foo = "notbar";
12401240
});
1241-
$( "#widget-wrapper" ).bind( "testwidgetfoo", function( event, ui ) {
1241+
$( "#widget-wrapper" ).on( "testwidgetfoo", function( event, ui ) {
12421242
equal( event.originalEvent, originalEvent, "original event object passed" );
12431243
deepEqual( ui, {
12441244
foo: "notbar",
@@ -1285,7 +1285,7 @@ test( "._trigger() - array as ui", function() {
12851285
this._trigger( "foo", null, [ ui, extra ] );
12861286
}
12871287
});
1288-
$( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) {
1288+
$( "#widget" ).on( "testwidgetfoo", function( event, ui, extra ) {
12891289
deepEqual( ui, {
12901290
foo: "bar",
12911291
baz: {
@@ -1328,7 +1328,7 @@ test( "._trigger() - instance as element", function() {
13281328
deepEqual( ui, { foo: "bar" }, "ui object passed to callback" );
13291329
}
13301330
});
1331-
$( instance ).bind( "testwidgetfoo", function( event, ui ) {
1331+
$( instance ).on( "testwidgetfoo", function( event, ui ) {
13321332
equal( event.type, "testwidgetfoo", "event object passed to event handler" );
13331333
deepEqual( ui, { foo: "bar" }, "ui object passed to event handler" );
13341334
});

ui/widget.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ $.Widget.prototype = {
313313
// we can probably remove the unbind calls in 2.0
314314
// all event bindings should go through this._on()
315315
this.element
316-
.unbind( this.eventNamespace )
316+
.off( this.eventNamespace )
317317
.removeData( this.widgetFullName );
318318
this.widget()
319-
.unbind( this.eventNamespace )
319+
.off( this.eventNamespace )
320320
.removeAttr( "aria-disabled" );
321321

322322
// clean up events and states
323-
this.bindings.unbind( this.eventNamespace );
323+
this.bindings.off( this.eventNamespace );
324324
},
325325
_destroy: $.noop,
326326

@@ -535,17 +535,17 @@ $.Widget.prototype = {
535535
eventName = match[ 1 ] + instance.eventNamespace,
536536
selector = match[ 2 ];
537537
if ( selector ) {
538-
delegateElement.delegate( selector, eventName, handlerProxy );
538+
delegateElement.on( eventName, selector, handlerProxy );
539539
} else {
540-
element.bind( eventName, handlerProxy );
540+
element.on( eventName, handlerProxy );
541541
}
542542
} );
543543
},
544544

545545
_off: function( element, eventName ) {
546546
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
547547
this.eventNamespace;
548-
element.unbind( eventName ).undelegate( eventName );
548+
element.off( eventName ).off( eventName );
549549

550550
// Clear the stack to avoid memory leaks (#10056)
551551
this.bindings = $( this.bindings.not( element ).get() );

0 commit comments

Comments
 (0)