mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Remove core event/alias and deprecated module dependencies
This commit is contained in:
parent
24f1ce9ea0
commit
e543253468
@ -139,7 +139,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// click to toggle enabled/disabled
|
// click to toggle enabled/disabled
|
||||||
$( "#disable" ).click(function() {
|
$( "#disable" ).on( "click", function() {
|
||||||
// use the custom selector created for each widget to find all instances
|
// use the custom selector created for each widget to find all instances
|
||||||
// all instances are toggled together, so we can check the state from the first
|
// all instances are toggled together, so we can check the state from the first
|
||||||
if ( $( ":custom-colorize" ).colorize( "option", "disabled" ) ) {
|
if ( $( ":custom-colorize" ).colorize( "option", "disabled" ) ) {
|
||||||
@ -150,7 +150,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// click to set options after initialization
|
// click to set options after initialization
|
||||||
$( "#green" ).click( function() {
|
$( "#green" ).on( "click", function() {
|
||||||
$( ":custom-colorize" ).colorize( "option", {
|
$( ":custom-colorize" ).colorize( "option", {
|
||||||
red: 64,
|
red: 64,
|
||||||
green: 250,
|
green: 250,
|
||||||
|
@ -131,7 +131,7 @@ test( "jQuery usage", function() {
|
|||||||
|
|
||||||
shouldCreate = true;
|
shouldCreate = true;
|
||||||
elem = $( "<div>" )
|
elem = $( "<div>" )
|
||||||
.bind( "testwidgetcreate", function() {
|
.on( "testwidgetcreate", function() {
|
||||||
ok( shouldCreate, "create event triggered on instantiation" );
|
ok( shouldCreate, "create event triggered on instantiation" );
|
||||||
})
|
})
|
||||||
.testWidget();
|
.testWidget();
|
||||||
@ -902,7 +902,7 @@ test( "_on() with delegate", function() {
|
|||||||
_create: function() {
|
_create: function() {
|
||||||
var uuid = this.uuid;
|
var uuid = this.uuid;
|
||||||
this.element = {
|
this.element = {
|
||||||
bind: function( event, handler ) {
|
on: function( event, handler ) {
|
||||||
equal( event, "click.testWidget" + uuid );
|
equal( event, "click.testWidget" + uuid );
|
||||||
ok( $.isFunction(handler) );
|
ok( $.isFunction(handler) );
|
||||||
},
|
},
|
||||||
@ -910,7 +910,7 @@ test( "_on() with delegate", function() {
|
|||||||
};
|
};
|
||||||
this.widget = function() {
|
this.widget = function() {
|
||||||
return {
|
return {
|
||||||
delegate: function( selector, event, handler ) {
|
on: function( event, selector, handler ) {
|
||||||
equal( selector, "a" );
|
equal( selector, "a" );
|
||||||
equal( event, "click.testWidget" + uuid );
|
equal( event, "click.testWidget" + uuid );
|
||||||
ok( $.isFunction(handler) );
|
ok( $.isFunction(handler) );
|
||||||
@ -923,7 +923,7 @@ test( "_on() with delegate", function() {
|
|||||||
});
|
});
|
||||||
this.widget = function() {
|
this.widget = function() {
|
||||||
return {
|
return {
|
||||||
delegate: function( selector, event, handler ) {
|
on: function( event, selector, handler ) {
|
||||||
equal( selector, "form fieldset > input" );
|
equal( selector, "form fieldset > input" );
|
||||||
equal( event, "change.testWidget" + uuid );
|
equal( event, "change.testWidget" + uuid );
|
||||||
ok( $.isFunction(handler) );
|
ok( $.isFunction(handler) );
|
||||||
@ -1005,7 +1005,7 @@ test( "_off() - single event", function() {
|
|||||||
widget._on( element, { foo: function() {
|
widget._on( element, { foo: function() {
|
||||||
ok( shouldTriggerWidget, "foo called from _on" );
|
ok( shouldTriggerWidget, "foo called from _on" );
|
||||||
}});
|
}});
|
||||||
element.bind( "foo", function() {
|
element.on( "foo", function() {
|
||||||
ok( shouldTriggerOther, "foo called from bind" );
|
ok( shouldTriggerOther, "foo called from bind" );
|
||||||
});
|
});
|
||||||
shouldTriggerWidget = true;
|
shouldTriggerWidget = true;
|
||||||
@ -1031,7 +1031,7 @@ test( "_off() - multiple events", function() {
|
|||||||
ok( shouldTriggerWidget, "bar called from _on" );
|
ok( shouldTriggerWidget, "bar called from _on" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
element.bind( "foo bar", function( event ) {
|
element.on( "foo bar", function( event ) {
|
||||||
ok( shouldTriggerOther, event.type + " called from bind" );
|
ok( shouldTriggerOther, event.type + " called from bind" );
|
||||||
});
|
});
|
||||||
shouldTriggerWidget = true;
|
shouldTriggerWidget = true;
|
||||||
@ -1059,7 +1059,7 @@ test( "_off() - all events", function() {
|
|||||||
ok( shouldTriggerWidget, "bar called from _on" );
|
ok( shouldTriggerWidget, "bar called from _on" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
element.bind( "foo bar", function( event ) {
|
element.on( "foo bar", function( event ) {
|
||||||
ok( shouldTriggerOther, event.type + " called from bind" );
|
ok( shouldTriggerOther, event.type + " called from bind" );
|
||||||
});
|
});
|
||||||
shouldTriggerWidget = true;
|
shouldTriggerWidget = true;
|
||||||
@ -1152,7 +1152,7 @@ test( "._trigger() - no event, no ui", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( document ).add( "#widget-wrapper" ).add( "#widget" )
|
$( document ).add( "#widget-wrapper" ).add( "#widget" )
|
||||||
.bind( "testwidgetfoo", function( event, ui ) {
|
.on( "testwidgetfoo", function( event, ui ) {
|
||||||
deepEqual( ui, {}, "empty ui hash passed" );
|
deepEqual( ui, {}, "empty ui hash passed" );
|
||||||
handlers.push( this );
|
handlers.push( this );
|
||||||
});
|
});
|
||||||
@ -1165,7 +1165,7 @@ test( "._trigger() - no event, no ui", function() {
|
|||||||
"callback"
|
"callback"
|
||||||
], "event bubbles and then invokes callback" );
|
], "event bubbles and then invokes callback" );
|
||||||
|
|
||||||
$( document ).unbind( "testwidgetfoo" );
|
$( document ).off( "testwidgetfoo" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test( "._trigger() - cancelled event", function() {
|
test( "._trigger() - cancelled event", function() {
|
||||||
@ -1180,7 +1180,7 @@ test( "._trigger() - cancelled event", function() {
|
|||||||
ok( true, "callback invoked even if event is cancelled" );
|
ok( true, "callback invoked even if event is cancelled" );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.bind( "testwidgetfoo", function() {
|
.on( "testwidgetfoo", function() {
|
||||||
ok( true, "event was triggered" );
|
ok( true, "event was triggered" );
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -1227,7 +1227,7 @@ test( "._trigger() - provide event and ui", function() {
|
|||||||
}, "ui object modified" );
|
}, "ui object modified" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#widget" ).bind( "testwidgetfoo", function( event, ui ) {
|
$( "#widget" ).on( "testwidgetfoo", function( event, ui ) {
|
||||||
equal( event.originalEvent, originalEvent, "original event object passed" );
|
equal( event.originalEvent, originalEvent, "original event object passed" );
|
||||||
deepEqual( ui, {
|
deepEqual( ui, {
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
@ -1238,7 +1238,7 @@ test( "._trigger() - provide event and ui", function() {
|
|||||||
}, "ui hash passed" );
|
}, "ui hash passed" );
|
||||||
ui.foo = "notbar";
|
ui.foo = "notbar";
|
||||||
});
|
});
|
||||||
$( "#widget-wrapper" ).bind( "testwidgetfoo", function( event, ui ) {
|
$( "#widget-wrapper" ).on( "testwidgetfoo", function( event, ui ) {
|
||||||
equal( event.originalEvent, originalEvent, "original event object passed" );
|
equal( event.originalEvent, originalEvent, "original event object passed" );
|
||||||
deepEqual( ui, {
|
deepEqual( ui, {
|
||||||
foo: "notbar",
|
foo: "notbar",
|
||||||
@ -1285,7 +1285,7 @@ test( "._trigger() - array as ui", function() {
|
|||||||
this._trigger( "foo", null, [ ui, extra ] );
|
this._trigger( "foo", null, [ ui, extra ] );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) {
|
$( "#widget" ).on( "testwidgetfoo", function( event, ui, extra ) {
|
||||||
deepEqual( ui, {
|
deepEqual( ui, {
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
baz: {
|
baz: {
|
||||||
@ -1328,7 +1328,7 @@ test( "._trigger() - instance as element", function() {
|
|||||||
deepEqual( ui, { foo: "bar" }, "ui object passed to callback" );
|
deepEqual( ui, { foo: "bar" }, "ui object passed to callback" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$( instance ).bind( "testwidgetfoo", function( event, ui ) {
|
$( instance ).on( "testwidgetfoo", function( event, ui ) {
|
||||||
equal( event.type, "testwidgetfoo", "event object passed to event handler" );
|
equal( event.type, "testwidgetfoo", "event object passed to event handler" );
|
||||||
deepEqual( ui, { foo: "bar" }, "ui object passed to event handler" );
|
deepEqual( ui, { foo: "bar" }, "ui object passed to event handler" );
|
||||||
});
|
});
|
||||||
|
12
ui/widget.js
12
ui/widget.js
@ -313,14 +313,14 @@ $.Widget.prototype = {
|
|||||||
// we can probably remove the unbind calls in 2.0
|
// we can probably remove the unbind calls in 2.0
|
||||||
// all event bindings should go through this._on()
|
// all event bindings should go through this._on()
|
||||||
this.element
|
this.element
|
||||||
.unbind( this.eventNamespace )
|
.off( this.eventNamespace )
|
||||||
.removeData( this.widgetFullName );
|
.removeData( this.widgetFullName );
|
||||||
this.widget()
|
this.widget()
|
||||||
.unbind( this.eventNamespace )
|
.off( this.eventNamespace )
|
||||||
.removeAttr( "aria-disabled" );
|
.removeAttr( "aria-disabled" );
|
||||||
|
|
||||||
// clean up events and states
|
// clean up events and states
|
||||||
this.bindings.unbind( this.eventNamespace );
|
this.bindings.off( this.eventNamespace );
|
||||||
},
|
},
|
||||||
_destroy: $.noop,
|
_destroy: $.noop,
|
||||||
|
|
||||||
@ -535,9 +535,9 @@ $.Widget.prototype = {
|
|||||||
eventName = match[ 1 ] + instance.eventNamespace,
|
eventName = match[ 1 ] + instance.eventNamespace,
|
||||||
selector = match[ 2 ];
|
selector = match[ 2 ];
|
||||||
if ( selector ) {
|
if ( selector ) {
|
||||||
delegateElement.delegate( selector, eventName, handlerProxy );
|
delegateElement.on( eventName, selector, handlerProxy );
|
||||||
} else {
|
} else {
|
||||||
element.bind( eventName, handlerProxy );
|
element.on( eventName, handlerProxy );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
@ -545,7 +545,7 @@ $.Widget.prototype = {
|
|||||||
_off: function( element, eventName ) {
|
_off: function( element, eventName ) {
|
||||||
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
|
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
|
||||||
this.eventNamespace;
|
this.eventNamespace;
|
||||||
element.unbind( eventName ).undelegate( eventName );
|
element.off( eventName ).off( eventName );
|
||||||
|
|
||||||
// Clear the stack to avoid memory leaks (#10056)
|
// Clear the stack to avoid memory leaks (#10056)
|
||||||
this.bindings = $( this.bindings.not( element ).get() );
|
this.bindings = $( this.bindings.not( element ).get() );
|
||||||
|
Loading…
Reference in New Issue
Block a user