diff --git a/src/data/Data.js b/src/data/Data.js index 476b3e1e2..a19476ea6 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -1,15 +1,14 @@ define( [ "../core", "../var/rnotwhite", - "./accepts" -], function( jQuery, rnotwhite ) { + "./var/acceptData" +], function( jQuery, rnotwhite, acceptData ) { function Data() { this.expando = jQuery.expando + Data.uid++; } Data.uid = 1; -Data.accepts = jQuery.acceptData; Data.prototype = { @@ -38,7 +37,7 @@ Data.prototype = { // We can accept data for non-element nodes in modern browsers, // but we should not, see #8335. // Always return an empty object. - if ( !Data.accepts( owner ) ) { + if ( !acceptData( owner ) ) { return {}; } diff --git a/src/data/accepts.js b/src/data/var/acceptData.js similarity index 70% rename from src/data/accepts.js rename to src/data/var/acceptData.js index 24e2f0ef0..6a1e5021b 100644 --- a/src/data/accepts.js +++ b/src/data/var/acceptData.js @@ -1,12 +1,9 @@ -define( [ - "../core" -], function( jQuery ) { +define( function() { /** * Determines whether an object can have data */ -jQuery.acceptData = function( owner ) { - +return function( owner ) { // Accepts only: // - Node // - Node.ELEMENT_NODE @@ -17,5 +14,4 @@ jQuery.acceptData = function( owner ) { return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); }; -return jQuery.acceptData; } ); diff --git a/src/event.js b/src/event.js index 8a059ca8a..233fd4348 100644 --- a/src/event.js +++ b/src/event.js @@ -6,11 +6,11 @@ define( [ "./var/slice", "./event/support", "./data/var/dataPriv", + "./data/var/acceptData", "./core/init", - "./data/accepts", "./selector" -], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv ) { +], function( jQuery, document, rnotwhite, hasOwn, slice, support, dataPriv, acceptData ) { var rkeyEvent = /^key/, @@ -376,7 +376,7 @@ jQuery.event = { // Native handler handle = ontype && cur[ ontype ]; - if ( handle && handle.apply && jQuery.acceptData( cur ) ) { + if ( handle && handle.apply && acceptData( cur ) ) { event.result = handle.apply( cur, data ); if ( event.result === false ) { event.preventDefault(); @@ -389,8 +389,8 @@ jQuery.event = { if ( !onlyHandlers && !event.isDefaultPrevented() ) { if ( ( !special._default || - special._default.apply( eventPath.pop(), data ) === false ) && - jQuery.acceptData( elem ) ) { + special._default.apply( eventPath.pop(), data ) === false ) && + acceptData( elem ) ) { // Call a native DOM method on the target with the same name name as the event. // Don't do default actions on window, that's where global variables be (#6170) diff --git a/src/manipulation.js b/src/manipulation.js index 55a77f4e8..227d0ef9e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -14,16 +14,16 @@ define( [ "./data/var/dataPriv", "./data/var/dataUser", + "./data/var/acceptData", "./core/init", - "./data/accepts", "./traversing", "./selector", "./event" ], function( jQuery, concat, push, access, rcheckableType, rtagName, rscriptType, wrapMap, getAll, setGlobalEval, buildFragment, support, - dataPriv, dataUser ) { + dataPriv, dataUser, acceptData ) { var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi, @@ -273,7 +273,7 @@ jQuery.extend( { i = 0; for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) { - if ( jQuery.acceptData( elem ) ) { + if ( acceptData( elem ) ) { if ( ( data = elem[ dataPriv.expando ] ) ) { if ( data.events ) { for ( type in data.events ) { diff --git a/test/unit/data.js b/test/unit/data.js index 3a90c0054..bb66447f0 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -819,32 +819,31 @@ QUnit.test( ".data doesn't throw when calling selection is empty. #13551", funct } } ); -QUnit.test( "jQuery.acceptData", function( assert ) { +QUnit.test( "acceptData", function( assert ) { assert.expect( 10 ); - var flash, pdf; + var flash, pdf, form; - assert.ok( jQuery.acceptData( document ), "document" ); - assert.ok( jQuery.acceptData( document.documentElement ), "documentElement" ); - assert.ok( jQuery.acceptData( {} ), "object" ); - assert.ok( jQuery.acceptData( document.createElement( "embed" ) ), "embed" ); + assert.equal( 42, jQuery( document ).data( "test", 42 ).data( "test" ), "document" ); + assert.equal( 42, jQuery( document.documentElement ).data( "test", 42 ).data( "test" ), "documentElement" ); + assert.equal( 42, jQuery( {} ).data( "test", 42 ).data( "test" ), "object" ); + assert.equal( 42, jQuery( document.createElement( "embed" ) ).data( "test", 42 ).data( "test" ), "embed" ); flash = document.createElement( "object" ); flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ); - assert.ok( jQuery.acceptData( flash ), "flash" ); + assert.equal( 42, jQuery( flash ).data( "test", 42 ).data( "test" ), "flash" ); pdf = document.createElement( "object" ); pdf.setAttribute( "classid", "clsid:CA8A9780-280D-11CF-A24D-444553540000" ); - assert.ok( jQuery.acceptData( pdf ), "pdf" ); + assert.equal( 42, jQuery( pdf ).data( "test", 42 ).data( "test" ), "pdf" ); - assert.ok( !jQuery.acceptData( document.createComment( "" ) ), "comment" ); - assert.ok( !jQuery.acceptData( document.createTextNode( "" ) ), "text" ); - assert.ok( !jQuery.acceptData( document.createDocumentFragment() ), "documentFragment" ); + assert.equal( undefined, jQuery( document.createComment( "" ) ).data( "test", 42 ).data( "test" ), "comment" ); + assert.equal( undefined, jQuery( document.createTextNode( "" ) ).data( "test", 42 ).data( "test" ), "text" ); + assert.equal( undefined, jQuery( document.createDocumentFragment() ).data( "test", 42 ).data( "test" ), "documentFragment" ); - assert.ok( jQuery.acceptData( - jQuery( "#form" ).append( "" )[ 0 ] ), - "form with aliased DOM properties" ); -} ); + form = jQuery( "#form" ).append( "" )[ 0 ]; + assert.equal( 42, jQuery( form ) .data( "test", 42 ).data( "test" ), "form with aliased DOM properties" ); +}); QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)", function( assert ) { assert.expect( 1 );