mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Support EventListener interface objects.
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventListener Fixes gh-1735
This commit is contained in:
parent
2525cffc42
commit
9877ca1a39
@ -117,6 +117,11 @@ jQuery.event = {
|
||||
selector = handleObjIn.selector;
|
||||
}
|
||||
|
||||
// Support objects implementing the EventListener interface.
|
||||
if ( handler && typeof handler.handleEvent === "function" ) {
|
||||
handler = handler.handleEvent.bind( handler );
|
||||
}
|
||||
|
||||
// Ensure that invalid selectors throw exceptions at attach time
|
||||
// Evaluate against documentElement in case elem is a non-element node (e.g., document)
|
||||
if ( selector ) {
|
||||
|
@ -45,6 +45,28 @@ QUnit.test( "on() with non-null,defined data", function( assert ) {
|
||||
|
||||
} );
|
||||
|
||||
QUnit.test( "on() with EventListener interface object", function( assert ) {
|
||||
|
||||
assert.expect( 4 );
|
||||
|
||||
var handler = {
|
||||
eventDelegateData: "can be found",
|
||||
handleEvent: function( event, data ) {
|
||||
assert.equal( data, 0, "non-null, defined data (zero) is correctly passed" );
|
||||
assert.equal( this.eventDelegateData, "can be found", "event delegate is accessible via this" );
|
||||
}
|
||||
};
|
||||
|
||||
jQuery( "#foo" ).on( "foo.on", handler );
|
||||
jQuery( "div" ).on( "foo.delegate", "#foo", handler );
|
||||
|
||||
jQuery( "#foo" ).trigger( "foo", 0 );
|
||||
|
||||
jQuery( "#foo" ).off( "foo.on", handler );
|
||||
jQuery( "div" ).off( "foo.delegate", "#foo" );
|
||||
|
||||
} );
|
||||
|
||||
QUnit.test( "Handler changes and .trigger() order", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user