mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Only attach events to objects that accept data - for real
There was a check in jQuery.event.add that was supposed to make it a noop
for objects that don't accept data like text or comment nodes. The problem was
the check was incorrect: it assumed `dataPriv.get( elem )` returns a falsy
value for an `elem` that doesn't accept data but that's not the case - we get
an empty object then. The check was changed to use `acceptData` directly.
(cherry picked from d5c505e35d
)
Fixes gh-4397
Closes gh-4558
This commit is contained in:
parent
c79e1d5fef
commit
f36f6abbb3
@ -6,13 +6,14 @@ define( [
|
||||
"./var/rnothtmlwhite",
|
||||
"./var/rcheckableType",
|
||||
"./var/slice",
|
||||
"./data/var/acceptData",
|
||||
"./data/var/dataPriv",
|
||||
"./core/nodeName",
|
||||
|
||||
"./core/init",
|
||||
"./selector"
|
||||
], function( jQuery, document, documentElement, isFunction, rnothtmlwhite,
|
||||
rcheckableType, slice, dataPriv, nodeName ) {
|
||||
rcheckableType, slice, acceptData, dataPriv, nodeName ) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -124,8 +125,8 @@ jQuery.event = {
|
||||
special, handlers, type, namespaces, origType,
|
||||
elemData = dataPriv.get( elem );
|
||||
|
||||
// Don't attach events to noData or text/comment nodes (but allow plain objects)
|
||||
if ( !elemData ) {
|
||||
// Only attach events to objects that accept data
|
||||
if ( !acceptData( elem ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2806,6 +2806,15 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as
|
||||
}, QUnit.config.testTimeout / 4 || 1000 );
|
||||
} );
|
||||
|
||||
QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
jQuery( document.createTextNode( "text" ) )
|
||||
.on( "focus", function() {} );
|
||||
|
||||
assert.ok( true, "No crash" );
|
||||
} );
|
||||
|
||||
QUnit.test( "Donor event interference", function( assert ) {
|
||||
assert.expect( 8 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user